we
Multi-mode text editor
The reason multi-mode generated
Four modes
- Normal mode
- Insert mode
- Command Mode
- Visual mode
we
man the vi
vim
vim normal mode
Enter directly vim or vim spaces in filenames Enter
i enter insert mode
I (shift + i) into insert mode, and the cursor reaches the beginning of the row
A , the next insertion location of the cursor position
A (shift + a) the rearmost, insert rows cursor
O, the next line is inserted into the line cursor , the original line sequentially following the cursor down one line
Before o
After o
O (Shift + O) , a line cursor in the row into the insert mode
Before O
After O
The normal mode (i.e., directly into the vim command mode):
h Left
j Down
K Move
l right
Arrow terminal may have garbled characters, it is recommended to master hjkl
y Copy
yy single-line copy
The cursor is located at a point yy
Move the cursor on the third line
Point p, copy
Copy to the fourth line
Click 3yy
The following three lines will display the copy, copy the execution point p
y $ (y + shift4), copying to the rearmost position of the cursor in the cursor line
Cut d
dd, cut line
d $, to the end position where the cursor shear
u withdrawal
ctrl + r, revoked wrong, redo
other
x, delete a single character, the cursor is moved to the target character, the point x, deleting the character
r, replacing a single character, the character cursor to the character, the point r, the input can be replaced
nG (11 + shiftg), move to the n-th line, such as 11G, moves to line 11
g, to the first line
G (shift + g), to the last line
^ (Shift6), move the cursor to the beginning of the line
$ (Shift4) end, move the cursor to the line
: Set nu, display line numbers
: Set nonu, cancel the line number
vim command mode
File Save
If you enter the vim,: w + path and file name to save
If vim spaces in filenames to enter,: w, save
:!(冒号叹号),后面跟linux命令,如查看IP地址
/目标字符,查找目标字符,n查找下一个
:s/old/new,用new替换old,默认只针对光标所在的行进行替换
:set nohlsearch,取消高亮显示
:%s/old/new,
:%s/old/new/g,全局替换
:3,5s/old/new,在第三行到第五行之间进行替换
设置配置文件
vim /etc/vimrc
最后一行添加
set nu
设置显示行号
vim可视模式,即选中
操作之前
ctrl+v,进入块可视模式
此时选中的可以是上下对齐的块
可以 对块进行批量操作
shift+i,即I
插入123,
按两次ESC
发现整个块前面都插入了123
也可以选中想要删除的块,按d删除