Basic usage of vim
1. Movement of the cursor
H move to the left
J move down
K move up
L (lowercase L) move to the right
Shift+6 (number 0) moves to the beginning of the line
Shift+4 moves to the end of the line
Gg moves to the first line
The end of the line of G movement
NG moves to the line where the number n is located
Ctrl+B turn the page forward
Ctrl+F turns the page backward
two。 Delete and paste
X delete one character backward X delete one character forward
Nx deletes n characters backward nX deletes n characters forward
Dd deletes a row
Ndd delete digits n lines
Yy replication
P cursor down copy P cursor up copy
U restore the operation of the previous step
V selected string
3. Edit mode
I insert before the current character
I insert at the beginning of the current line
An insert after the current character
An insert at the end of the current line
O insert a line under the line where the cursor is located
O insert a row on the line where the cursor is located
4. Command mode
/ word look for a string behind the cursor and press n to continue the search
? Word looks for a string before the cursor and presses n to continue the search
: N1 word1 n2sqqqqword1max Word2max g look for word1 between N1 and N2 lines and replace it with word2 without adding g, then only the first word1 of each line is replaced.
: 1 word2 word2 in the document without g, only the first word1 of each line will be replaced
W save text
: Q exit vim
: w! Forced save, which can be completed even if the text is read-only under root users
: q! Forced exit, all changes will not take effect
Wq saves and exits
: set nu displays the line number
: set nonu does not display line numbers