General mode: move the cursor
H or move a character toward the left arrow key
J or downward arrow key (arrow) move the cursor down a character
K or move a character up with the cursor
L or right direction key (→) move the cursor one character to the right
If you want to move multiple times, for example, move 30 rows down, you can use a combination of "30j" or "30 Gbit/s", that is
After adding the number of times (number) You want to perform, press the action!
[Ctrl] + [f] the screen moves one page down, which is equivalent to a [PageDown] button (commonly used)
[Ctrl] + [B] The screen moves one page up, which is equivalent to a [PageUp] button (commonly used)
[Ctrl] + [d] Move the screen down half page
[Ctrl] + [u]
0 this is the number "0": Move to the top character of this line (commonly used)
$ Move to the last character of this line (commonly used)
H move the cursor to the top line of the screen
M move the cursor to the center of the screen
L move the cursor to the bottom line of the screen
G moves to the last line of the file (frequently used)
NG moves to the nth line of the file (commonly used)
Gg moves to the 1st rows of this file
N <space> the cursor moves n characters from the row to the right.
N <Enter> n is a number. Move the cursor down n rows (commonly used)
General mode: search and replace
/Word searches for a string named word under the cursor.
? Word searches for a string named word on top of the cursor.
N is an English button. Indicates the meaning of "repeating the previous search action.
N is the opposite of n, which is the previous search action for "reverse.
: N1, n2s/word1/word2/g
N1 and n2 are numbers. Search for the word1 character string between line n1 and line n2 and replace it with word2!
: 1, $ s/word1/word2/g
Search for the word1 string from the first row to the last row and replace it with word2! (Common)
: 1, $ s/word1/word2/gc
Search for the word1 string from the first row to the last row and replace it with word2! The prompt characters are displayed before replacement to confirm whether the conform must be replaced! (Common)
General mode: delete, copy, and attach
X, X in a row, x is to delete a character backward, X is to delete a character forward
Nx n is a number and n characters are deleted consecutively.
Dd deletes the entire column of the cursor (commonly used)
Ndd deletes the down n column where the cursor is located,
D1G delete all data from the cursor to the first row
DG deletes all data from the cursor to the last row
D $ Delete the cursor to the last character of the row
D0 is the number 0, where the cursor is deleted, to the beginning of the row.
Yy copy the row of the cursor (commonly used)
Nyy copies the n-down column where the cursor is located,
Y1G copy all data from the cursor column to the first column
YG copies all data from the cursor column to the last column
Y0 copies the character of the cursor to all data at the beginning of the row.
Y $ copy all data from the character with the cursor to the end of the row
Select the v character, and the position where the cursor passes is reversed.
Line V is selected, and the line through which the cursor passes is reversed
Y. Copy the reverse IP address.
D. Delete the whitelist.
P: to paste the copied data in the next row of the cursor,
P is the row that is pasted on the cursor!
U restores the previous action. (Common)
[Ctrl] + r redo the previous action. (Common)
Enter edit in Normal Mode
I, I
Insert: insert the input text at the position of the current cursor. The existing text will be backward
Here, I is "insert from the current cursor", I is "in the current
Insert the row at the first non-space character 』. (Common)
A,
A is "insert from the next character where the current cursor is located", and A is "from the light
Start to insert at the last character of the row where the mark is located 』. (Common)
This is the case of the English letter o.
O, O
O is "Insert a new row in the next row where the current cursor is located 』
O inserts a new row into the previous row where the current cursor is located!
R, R
Replace: r will replace the character where the cursor is located; R will always replace the character where the cursor is located
Text until you Press ESC; (commonly used)
Exit the editing mode of Esc and return to normal mode (commonly used)
Command Line Mode: Switch to normal mode using ESC
: W writes the edited data to the hard disk file (commonly used)
: Q leaves vi (commonly used)
: Q! If you have modified an archive and do not want to store it, use it! To force exit without storing files.
: Wq
: Wq! It is forced to save and leave (commonly used)
: Setnu: displays the row number. After this parameter is set, the prefix of each row is displayed.
: Setnonu undisplay the row number
: R [filename] reads data from another file when editing data
Recommended reading:
Vim Learning Guide
Quick learn Vi Editor
Powerful Vim Editor
Build a Vim Development Environment on CentOS 6.2
Vim 7.4a released, a new and faster Regular Expression Engine
Install the highlighted Vim editing tool in CentOS 5.4
Vim tips: C language settings
Set the Vim row number in Ubuntu