The screen moves down one page, equivalent to [Page Down] (commonly used)
[ctrl]+[b]
The screen moves up one page, equivalent to [Page Up] (commonly used)
[ctrl]+[d]
Move the screen down by half a page
[ctrl]+[u]
Move the screen up by half a page
n+[Space]
n represents a number, press the number and then press the space bar, the cursor will move to the right to the nth character of this line.
Function key [Home] or 0
Move the cursor to the first character of the line
Function key [End] or $
Move the cursor to the last character of the line (commonly used)
H
Move the cursor to the first character of the line at the top of the screen
M
Move the cursor to the first character of the line in the center of this screen
L
Move the cursor to the first character of the bottom line of this screen
G
Move the cursor to the last line of this file (commonly used)
nG
n is a number. Move cursor to line n of this file
gg
Move the cursor to the first line of this file (commonly used)
n+[Enter]
n is a number. Move the cursor down n rows (commonly used)
1.2 Search and replace
button
illustrate
/word
Look down at the current cursor position to find the string with the keyword word (commonly used)
?word
Look up the string with the keyword word at the current cursor position
n
Here n is the key n. Represents repeating the previous search action
N
Here N is key N. The function is the opposite of n, representing the reverse execution of the previous search action
:n1,n2s/word1/word2/g
Both n1 and n2 are numbers, indicating the number of rows. The word1 string can be found between lines n1 and n2 and replaced with word2 (common)
:1,$s/word1/word2/g
Indicates that from the first line to the last line, replace the word1 string with word2 (commonly used)
:1,$s/word1/word2/gc
Indicates that from the first line to the last line, it also replaces the word1 string with word2, the difference is that the prompt character is displayed before the replacement, and the user confirms whether the final replacement (commonly used)
* When using /word, combined with n or N, the search can become very convenient :)
1.2 Delete, copy and paste
button
illustrate
[Del] or x
Delete one character backward (common)
X
Delete one character forward (common)
nx
n is a number, which means to delete n characters in a row
dd
Delete the row where the cursor is located (commonly used)
ndd
n is a number, delete n rows from the row where the cursor is located (commonly used)
d1G
Delete all data from the row where the cursor is located to the first row
dG
Delete all data from the row where the cursor is located to the last row
d$
Delete the cursor to the last character of the row
d0
is the number 0, delete the cursor to the first character of the row
yy
Copy the row where the cursor is located (commonly used)
nyy
n is a number, copy the row where the cursor is located and count down n rows (commonly used)
y1G
Copy all data from the row where the cursor is located to the first row
which
Copy all data from the row where the cursor is located to the last row
y0
Copy the character where the cursor is located to all the data at the beginning of the line
y$
Copy the character where the cursor is located to all data at the end of the line
p
Paste the copied data in the row below the row where the cursor is located (commonly used)
P
将已复制的数据粘贴在游标所在的那一行的上一行,原来游标所在的那一行会被推后一行 (常用)
J
将游标所在的行与下一行的数据合并为一行
u
撤销前一个操作 (常用)
[ctrl]+r
重做上一个被撤销的操作 (常用)
.
这是小数点,表示重复前一个操作 (常用)
* 最后三个按键乃是神器,熟悉后记得经常使用它们,会让你觉得使用 vim 是一件很快乐的事情哦 :)