Common Vim commands 1 switch insert mode: In command mode, insert a (in lowercase) after the cursor, insert A (in upper case) at the end of the line where the cursor is located, insert I (in lower case) insert I (uppercase) before the cursor start insert I (uppercase) insert o (lowercase) at the beginning of the row where the cursor is located insert a new empty line insert O (uppercase) insert an empty row before the row where the cursor is located
Common Vim commands
1. switch the insert mode:
In command mode
Insert after a (lower case) cursor
A (uppercase) insert at the end of the row where the cursor is located
I (lower case) insert before the cursor
Insert at the beginning of the line where I (uppercase) cursor is located
O (lower case) insert an empty row after the cursor row
O (uppercase) insert an empty row before the row where the cursor is located
Press ESC in insert mode to return to command mode
2 switch to edit mode
In command mode, Press [:] to enter edit mode. after you press enter, the system automatically returns to command mode or press ESC to return to command mode.
3. Save the file
Editing mode
: W (lower case) save the file
: Wq (lower case) save and exit vim
: W file name 1 save the file as file name 1
: ZZ (uppercase) save the file and exit, equivalent to: wq
: Wq! (Lower case) the file owner forces to save the read-only file. if this operation is not performed by the file owner, the operation fails.
: Q! Exit and do not save the file
4. copy (yank)
In command mode
Yy or Y copy the entire row of the cursor
Y ^ copy to the beginning of the row where the cursor is located, excluding the cursor position characters
Y $ copy to the end of the row where the cursor is located, including the cursor position character
Yw copies a word and the cursor must be in the word header.
Copy yG to the end of the file
Copy y1G to the beginning of the file
Nyy copies the n rows starting with the row where the cursor is located.
5 paste
In command mode
P (lower case) after pasting to the cursor
P (uppercase) paste to front of the cursor
6. delete
In command mode
X (lower case) deletes the character before the cursor
X (uppercase) delete the character after the cursor
Dd (lower case) deletes the entire row where the cursor is located
Dw (lower case) deletes a word at the cursor
DG delete the entire row where the cursor is located to the end of the file
Dgg deletes the entire row where the cursor is located to the beginning of the file
D (uppercase) is deleted to the end of the line, containing the characters at the cursor
D $ has the same effect as D
D0 is deleted to the beginning of the line, excluding the characters at the cursor
D ^ has the same effect as d0
: N1, n2d edit mode, delete n1-n2 rows
7. Undo
In command mode
U (lower case) undo before infinite save (about 500 times)
Ctrl + r redo
8-character replacement
In command mode
R (lower case) replaces the cursor with a character
R (uppercase) begins to replace until you press ESC to exit the replace, which is equivalent to pressing the keyboard to the insert key
Cc (lower case) replaces the entire line where the cursor is located
S (uppercase) has the same effect as ss (lowercase)
C (uppercase) is replaced by the end of the line, including the character at the cursor
C0 (lowercase, number 0) is replaced by the first line, excluding the characters at the cursor
C ^ (lower case) and c0 (lower case, number 0) have the same effect
9 string search and replacement
In command mode
/String start from the cursor and start to look down the string
/In the search mode, search for the next one by n (lower case) and the last one by N (upper case ).
? String starts from the cursor and starts to look up the character from string
? In search mode, Click n (lower case) to find the previous one, and then click N (upper case) to find the next one.
*