Linux command the whole network the most complete 5 (vim editor)

Five .vim Editor

1.vim Profile

(Particularly important in the terminal)
vi and vim is the editor in Linux, the difference is, the more advanced vim, can be regarded as
vim: more suitable for writing code
vim focus on cursor movement mode switch, delete, search, replace, copy, paste, undo commands use

2.vim three modes

vim中存在三种模式(大众的认知):命令模式,编辑模式(输入模式),末行模式(尾行模式)
*-* 命令模式:在该模式下是不能对文件直接编辑,可以输入快捷键进行一些操作(删除行,复制行,移动光标,粘贴等等)【打开文件默认进入的模式】
*-* 编辑模式:在该模式下可以对文件的内容进行编辑
*-* 末行模式:可以再末行输入命令来对文件进行操作(搜索,替换,保存,退出,撤销,高亮等等)
vim打开文件的方式(4中,要求掌握的就前三种)
#vim 文件路径      
    作用:打开指定文件
#vim +数字 文件的路径                
    作用:打开指定文件,并将光标移动到指定行
#vim +/关键词 文件的路径              
    作用:打开指定文件,并且高亮显示关键词
#vim 文件路径1 文件路径2 文件路径3    
    作用:同时打开多个文件

Focus: a copy go to / etc / passwd file, copied to the current directory #cd #cp / etc / passwd ~ /
exit mode: Enter ": q" Press Enter to

1. Command Mode

Note: This mode is to open the file mode first seen (you can open the file to enter)

1. Move the cursor

(1).光标移动到行首      按键:shift+6 或 ^ (T字母上面的6,不要按小键盘的6)
(2).光标移动到行尾      按键:shift+4 或 $ (R字母上面的4,不要按小键盘的4)
(3).光标移动到首行      按键:gg
(4).光标移动到末行      按键:G
(5).翻屏
     向上翻屏:按键:ctrl + b     或      PgUp
     向上翻屏:按键:ctrl + f     或      PgDn

2. Copy operation (to be used together with the paste)

(1).复制光标所在行      按键:yy
      粘贴:在想要复制的地方按下p键      
(2).**以光标所在行为准(包含当前行),向下复制指定的行数       
      按键:数字 yy
(3).可视化复制      
      按键:ctrl + v

3. Cut / delete

(1).**剪切/删除光标所在行       
      按键:dd (删除之后下一行下移)
      注意:dd严格意义上说是剪切命令,但是如果剪切了不粘贴就是删除
(2).**剪切/删除光标所在行为准,向下删除/剪切指定的行
      按键:数字 dd
(3).剪切/删除光标所在当前行,但是删除之后下一行不上移     
      按键:D    (删除之后变成空白行)

4. Undo / Redo

      撤销:输入u           (undo)
      恢复:ctrl + r        (取消之前的撤销)

5. Extended 1: rapid movement of the cursor

(1).**快速将光标移动到指定的行数                 
      按键:数字 G
(2).**以当前光标为准向上/上下移动n行             
      按键:数字 上下方向键
(3).以当前光标为准向左/向右移动n字符          
      按键:数字 左右方向键
(4).末行模式下的快速移动方式:移动到指定的行   
      按键:输入英文":",其后输入行数字,按下回车

2. Mode switching between

  • Command mode -> Input line mode ":" (colon)
  • Command mode -> the like Edit Mode Press ia
  • Line mode, Edit mode -> press esc
  • Double-click the line mode esc, delete all command in the last line

3. line mode

1.保存操作(write)     
      输入:"w"           保存文件
      输入:"w 路径"      另存为
2.退出(quit)          
      输入:":q"          退出文件
3.保存并退出	      
      输入:":wq"         保存并退出
4.强制退出(l)         
      输入:":ql"         表示强制退出,刚才做的修改操作不保存
5.调用外部命令(了解)  
      输入:":!外部的命令"
6.搜索/查找           
      输入:"/关键词"      在搜索结果中切换上/下一个结果:N/n     (next)
      如果需要取消高亮,则需要输入:":nohl"【no high light】
7.替换  
      :s/搜索的关键词/新的内容       替换光标所在行的第一处符合条件的内容容
      :s/搜索的关键词/新的内容/g     替换光标所在行的全部符合条件的内容
      :%s/搜索的关键词/新的内容      替换整个文档中每行第一个的符合条件的内容
      :%s/搜索的关键词/新的内容/g    替换整个文档的符合条件的内容
            %表示整个文件
            g表示全局
8.显示行号      
      输入:":set nu" 【number】
      取消        输入:":set nonu"number】
9.扩展(2):
      使用vim同时打开多个文件,在末行模式下进行切换文件
      查看当前已经打开的文件名称:输入:":files"
      在%a的位置有2种现实可能:
            %a:active,表示当前正在打开的文件
            #:表示上一个打开的文件
      切换文件的方式:
            a:如果需要指定切换文件的名称,则可以输入:":open 已经打开的文件名"
            b:可以通过其他命令来切换上一个文件/下一个文件
      输入:":bn" 切换到下一个文件(back next)
      输入:":bp" 切换到上一个文件(back prev)

4. Edit mode

Entry mode: Key see two ways to enter: i (start inserting before the character under the cursor), a (start inserting after the character under the cursor)
Exit: Press "esc"

5. practical function

1. The code coloring

  • Case: First create a simple c language program
    how to control the coloring or not?
      显示:":syntax on"
      关闭显示:":syntax off"

Use the calculator 2.vim

When suddenly need to use a calculator when editing the file to calculate some formulas, at this time need to use a calculator, but need to exit, vim itself incorporates a simple calculator

      a.进入编辑模式
      b.按下按键"ctrl + R",然后输入"=",此时光标会变到最后一行
      c.输入需要计算的内容,按下回车

Guess you like

Origin blog.csdn.net/affluent6/article/details/91543640