Method for moving the cursor
[Crtl] + [f] Move one page down the screen
[Crtl] + [B] Move one page up
0 or the function key home, move to the top character of this line
$ Or function key end, move to the character at the end of the line
G moves to the last row of the file.
NG moves to the nth row of the file, where n is a number.
Gg moves to the first line of the file
N [enter] move the cursor down n rows. n is a number.
U restore the previous operation
[Crtl] + r redo the previous operation
. Decimal point. Repeat the previous operation
2. search and replace
/Word looks down for a string named word
? Word
N repeated downward search
N multiple Lookup
: N1, n2s/word1/word2/g n1, n2 is a number, search for the word1 line from n1 to n2 and replace it with word2
: 1, $ s/word1/word2/g search for the word1 from row 1 to the last row and replace it with word2
: 1, $ s/word1/word2/gc search for the word1 line from 1 to the last line and replace it with word2, and prompt the user to confirm the information
3. Delete, copy, and paste
X, X x = [Backspace], X = [delete]
Nx deletes n characters consecutively and n is a number.
Dd deletes the entire row
Ndd deletes n rows and n digits down.
Yy copy the row where the cursor is located
Nyy copies the n-down line of the cursor
P, P p paste the cursor in the next line, P paste the cursor in the previous line
4. Enter the insert or replace mode.
I, I I insert at the cursor position, I start to insert at the first non-space character in the current row
A, A a: insert the cursor next character, and A: insert the cursor from the last character in the row where the cursor is located.
O, O o Insert the cursor in the next row, and O Insert the cursor in the previous row.
R, R r replace the character where the cursor is located once, R always replace
5. Save and exit the command line
: W save
: W! Force write save
: Q exit vi
: Q! If the modification is not saved, force exit
: Wq save and Leave vi
:! Show shell commands in command vi Mode
: Set nu display row number
: Set nonu cancel row number
: W [filename] Save As filename File
Six choices
V, V, [crtl] + v
V character selection
Select row V
[Crtl] + v Quick Selection
Y copy the selected block
D. Delete the selected block.
Seven-plus file editing
Vim/etc/hosts/etc/man. cfg
One vim opens two files.
: N: edit the next file
: N: edit the previous file
: File: list all files opened by vim.
In this case, copying is very simple. It is a bit interesting to share the clipboard.
More than 8 window functions
Two cases
1. A file is too large. If you want to compare the files before and after, you can use multiple windows.
2. There are two files to be compared. If you do not want to edit multiple files, you can use multiple windows.
: Sp [filename] open a new window. If no file name is added, split the window into the current file. Otherwise, multiple files will be created.
[Ctrl] + w + j
[Ctrl] + w + down key method, press [ctrl] Not to put it, then press w to open all the buttons, then press j (down key ), move the cursor to the window below
[Ctrl] + w + k
[Ctrl] + w + The up key is the same as above, but the window is moved to the top
[Ctrl] + w + q exit window
Or: q