vi / vim editor Basic Operation

A, vi / vim three modes

vi editor has three modes: command mode (command mode), insert mode (Insert mode), the bottom line mode (last line mode).

Is that you open a file directly with the command (vi filename), the default is in command mode. In command mode is not directly edit the text you type the letters will be treated as command execution. Such as input i, the input means before the current cursor, and switches to the insert mode. In insert mode, you can edit the text. In insert mode you can press Esc to return to command mode.

In command mode, you can switch by entering :( colon) in the end-line mode, the bottom line mode can do something to save, character replacement and other operations, under command line mode to enter the end, an exit or return to command mode, or double-click Esc to return to command mode. For example wq then Enter to indicate to save and exit the editor.

Insert mode and the line mode can not switch to the command through mode.

                                  

Entering line mode, the bottom will be prompted colon; insert mode, the bottom will be prompted --INSERT--. If not, the bottom line into the first mode, the input set showmode + Enter to display the prompt.

 

 

Two, vi / vim basic commands

1, vi editor to enter and exit

To: 1, the command input window vi / vim press Enter to enter editing interface

   2, select File Open selection vi / vim editor

Exit: In the line mode, enter a colon Q! Press Enter to exit without saving;

   Behind the colon wq press Enter to save and exit

2, paste, copy and delete operations

----命令模式:----

yy             复制光标所在行
2yy            复制光标所在行开始的2行
p              粘贴
dd             删除光标所在行(实际是剪切)
3dd            删除光标所在行开始的3行(剪切)
x              删除当前光标所在的字符
X(大写)       删除当前光标前一个字符

 3, movement of the cursor

----命令模式:----

h 左移   j 下移 k 上移  l 右移 (四个箭头也可以上下左右移动)
H 当前屏幕第一行
M 当前屏幕中间
L 当前屏幕最后一行
ctrl+f  往下翻页
ctrl+b  网上翻页
G       定位到最后一行(整个文档最后一行)
5G      定位到第5行
gg      定位到第一行(整个文档第一行)
w       跳到下一个单词
b       跳到上一个单词
{       移动到上一个代码块
}       移动到下一个代码块
v、V    先按v再用上下箭头选中几行,再>         这几行集体右移,再.继续右移 
v、V    先按v再用上下箭头选中几行,再<         这几行集体左移    
                                   

4. Other

----命令模式:----

u            撤销
ctrl+r       反撤销(撤销u操作)
r            修改当前字符
R            从当前位置开始修改,按Esc返回
/            搜索,先输入/,再输入搜索内容+回车。n、N表示上(下)一个搜索结果

5, line mode

  ----底行模式:----

q!           不保存退出

wq           保存退出

%s/abc/123/g     把全文的abc替换成123

1,10s/abc/123/g   把1-10行的abc替换成123

 



以上转载自:https://blog.csdn.net/xing851483876/article/details/84553945

 

Guess you like

Origin www.cnblogs.com/-citywall123/p/11373592.html