vim Three modes: General mode edit mode Command mode
Copy and paste content can be deleted in general mode
To move the cursor :
[Ctrl]+[f]: The screen moves down one page, equivalent to the [PageDown] button.
[Ctrl]+[b]: The screen moves up one page, equivalent to the [PageUp] button.
0 or function key [Home]: Moves to the front character of this line.
$ or Function key [end]: moves to the last face character of this line.
G: Move to the last line of this file.
GG: Move to the first line of this file, equivalent to 1G.
N[enter]:n is a number, the cursor moves down n rows.
Find and Replace:
/word: Look down for a string called Word.
Word: Look up a string called word.
: n1,n2s/word1/word2/g: Find the Word1 string between line N1 and N2, and replace it with Word2.
: 1, $s/word1/word2/g: look for the word1 string from the first line to the last line, and replace it with Word2.
: 1, $s/word1/word2/gc: look for the word1 string from the first line to the last line, and replace it with WORD2. and display the prompt character before the replacement to confirm that the user needs to be replaced.
Delete, copy, and paste:
X,x: In a line of words, X is the backward deletion of one character (equivalent to the [Del] key), and X is a character (equivalent to [Backspace]) that is deleted forward.
DD: Deletes the entire line where the cursor is located.
NDD: Deletes the downward n-row of the cursor.
YY: The line where the cursor is copied.
Nyy: The next n line where the cursor is copied.
P,p:p pastes the copied content on the next line of the cursor, and P is pasted on the previous line of the cursor.
U: Restores the previous operation.
[Ctrl]+r: Redo the previous operation.
. : The decimal point, repeating the previous action.
General mode switch to edit mode:
I,i: Enter insert mode, I is inserted from the current cursor location. I begin the insertion at the first non-whitespace character at the current row.
A,a: Enter insert mode. A is the insertion starting at the next character where the cursor is currently located. A is inserted starting at the last character of the row.
O,o: Enter insert mode. O is inserted on the next line. O is inserted on the previous line.
R,r: Enter replacement mode. R replaces only the same character as the cursor. R will always replace the character of the cursor until the ESC key is pressed.
General mode switch to command line:
: W: Writes the edited data to the hard disk.
: Q: Leave VI behind add! To force leave.
: Wq: Leave after saving. : wq! to leave after forced save.
Vim Common commands