Scope of application: a beginner who has some knowledge of vim.
1 General Mode
Move cursor |
H or ← |
The cursor moves one character to the left |
J or ↓ |
Move the cursor down one character |
K/↑ |
Move the cursor up one character |
L or → |
The cursor moves one character to the right |
n+ (h,j,k,l or ←,↓,↑,→) |
The cursor moves n characters (lines) in the specified direction |
Ctrl+f |
The screen moves down one page |
Ctrl+b |
The screen moves up one page |
Ctrl+d |
The screen moves down half a page |
Ctrl+u |
The screen moves up half a page |
+ |
Cursor moves to the next column of non-whitespace |
- |
Cursor moves to the previous column of non-whitespace |
N+space |
The cursor moves n characters to the right |
0 or home |
The cursor moves to the beginning of the bank |
$ or end |
Move cursor to end of bank line |
H |
Cursor moves to the beginning of the first line of the screen |
M |
Cursor moves to the beginning of the middle line of the screen |
L |
Cursor moves to the beginning of the last line of the screen |
G |
Cursor moves to the beginning of the last line of the file |
N+g |
The cursor moves to the beginning of the first n line of the file |
N+enter |
Move the cursor down n rows |
Search and replace |
/word |
Find word strings under the cursor |
? word |
Find word strings above the cursor |
N |
Repeat a previous search action |
N |
Reverse repeat the previous search action |
: n1,n2s/word1/word2/g |
N1,N2 is a number. Use Word2 to replace word1 between N1 and N2 rows |
: 1, $s/word1/word2/g |
Full text replace word1 with Word2 |
: 1, $s/word1/word2/gc |
Full text replaces word1 with Word2, and displays prompt characters before replacement to confirm if a replacement is required |
Delete, copy, and paste |
X,x |
In one row, X deletes a character backwards, and X deletes one character forward |
N + x |
Delete the first n characters of the cursor continuously |
N + X |
Continuous deletion of n characters after the cursor |
Dd |
Delete the cursor in the row |
N+dd |
Delete the row where the cursor is down n |
D+n+g |
Delete all data from cursor to nth row |
Dg |
Delete all data from the cursor to the last row |
d$ |
Remove all data from the last character of the line cursor |
D0 |
Remove all data from the first character of the line to the cursor |
Yy |
Copy data from the row where the cursor is located |
N+yy |
Copy all data on the down n rows of the cursor |
Y+n+g |
Copy all data from row to n row of cursor |
YG |
Copy all data from the row to the last row of the cursor |
Y0 |
Copy all data at the beginning of the line at the cursor location |
y$ |
Copy all data where the cursor is at the end of the line |
P |
Paste copied content on the next line of the cursor |
P |
Paste copied content on one line of the cursor |
J |
Merges the row of the cursor with the next row into the same row |
U |
Undo previous Action |
Ctrl+r |
Redo a previous action |
. (decimal point) |
Repeat a previous action |
Block selection |
V |
Character selection, place the cursor over a local anti-white selection |
V |
Row selection, and the line that the cursor passes through is white-selected |
CTRL + V |
Block selection, available in rectangular selection |
Y |
Copy anti-white selection |
D |
Remove anti-white selection |
2. General mode switch to edit mode
Enter INSERT or replace |
I |
Insert mode: Inserts from the current cursor location |
I |
Insert mode: Inserts the first non-whitespace space at the current row |
A |
Insert mode: Inserts from the current cursor's next character prompt |
A |
Insert mode: Starts at the last character of the line where the cursor is located |
O |
Insert mode: Inserts a new line at the next line where the cursor is currently located |
O |
Insert mode: Inserts a new line on the previous line where the cursor is currently located |
R |
Replace mode: Replaces the one character where the cursor is located |
R |
Replace mode: Always replace the text in the cursor until you press ESC |
Esc |
Exit edit mode, return to normal mode |
3. General mode switch to instruction mode
Instruction column Command |
: W |
Write the edited data to the drive file |
: w! |
If the file property is read-only, the archive is forced to write |
: Q |
Leave vim |
: q! |
If you change the file, do not want to store, forced to leave not to store files |
: Wq |
Left after storage |
: wq! |
Forced to leave after storage |
Zz |
If the file has not been changed, do not store the leave, if the file has been changed, save and leave. |
: w [filename] |
Save the edited data to another file |
: R [FileName] |
Reads another profile data into the edited data, and adds it to the line following the cursor |
: n1,n2 w [filename] |
Store the contents of N1 to N2 as a filename file |
:!command |
Temporarily leave Vim to execute shell command in instruction mode |
: Set Nu |
Show line Numbers |
: Set Nonu |
Suppress line numbers |
Multi-file editing |
: N |
Edit Next file |
: N |
Edit Previous file |
: Files |
List all the files that are currently open for VIM |
Multi-window |
: SP [filename] |
Open a new window, if the Add filename means to open a new file in a new window, otherwise two windows are the same file content (synchronized display) |
CTRL + W + J or ctrl + W +↓ |
Cursor moves to the lower window |
Ctrl + W + K or ctrl + W +↑ |
Cursor moves to the upper window |
Ctrl + W + q |
End Cursor Window |
Quick mastery of VIM: Shortcut key Operations Command Daquan