Basically, vi/vim is divided into three modes: Command mode, Insert mode and Last line mode
In command mode
1. Move the cursor p>
w(e) Move the cursor to the next word
b move to a word on the cursor
The number 0 moves to the beginning of this line
$ move the cursor to the end of the line
H move the cursor to the first line of the screen
M Move the cursor to the middle line of the screen
L move the cursor to the end of the screen
gg Move the cursor to the first line of the document
G move the cursor to the end of the document
ctrl + f Next
ctrl + b Previous
`. Move the cursor to the last modified line
2. Find
/chaoge Search the chaoge string in the entire document, and look down
?chaoge Search the chaoge string in the entire document and look up
* Find the entire document, match all the words where the cursor is located, press n to find the next place, N to the previous place
# Find the entire document, match all words where the cursor is located, press n to find the next place, and N to the previous place
gd Find the word that matches the word under the cursor, and stay on the first match that is not annotated
% find the other half of the bracket! !
3. Copy, delete, paste
yy copy the line where the cursor is
dd delete the line where the cursor is
D delete the current cursor to the end of the line
dG delete the current line to the end of the document
p Paste the content copied by yy
x delete the character under the cursor
u Undo the operation of the previous step
4. Numbers and commands
3yy copy the 3 lines where the cursor is
5dd delete the 5 lines where the cursor is located
in input mode
i
a
o
Underline command mode
< pre>:q! Force exit
:wq! Force write exit
:set nu display line number
:The number is adjusted to the number line
:wq! Force write exit
:set nu display line number
:The number is adjusted to the number line
Press esc at any time to exit the bottom line command mode
:! command Temporarily leave vim command mode, the result of executing command
For example:!ip a Temporarily look at the ip information, and then you can go back to vim
:set nu display vim line number
:set nonu cancel line number
< span style="color: #000000;">How to move the cursor
h or the left arrow key (←) moves the cursor one character to the left
j or down arrow key (↓) to move the cursor down one character
k or up arrow key (↑) Move the cursor one character up
l or right arrow key (→) Move the cursor one character to the right
Move down 5 lines 5j
Move 10 characters to the right 10l
n(space) Press the number n, such as 10, and then press the space, the cursor will move 10 characters to the right
w(e) move the cursor to the next word
b move to a word on the cursor
The number 0 moves to the beginning of this line
$ move the cursor to the end of the line
H move the cursor to the first line of the screen
M Move the cursor to the middle line of the screen
L move the cursor to the end of the screen
gg Move the cursor to the first line of the document
G move the cursor to the end of the document
ctrl + f Next
ctrl + b Previous
`. Move the cursor to the last modified line
/chaoge in the entire document Search for the chaoge string in, find down
?chaoge Search the chaoge string in the entire document and look up
* Find the entire document, match all the words where the cursor is located, press n to find the next place, N to the previous place
# Find the entire document, match all words where the cursor is located, press n to find the next place, and N to the previous place
gd Find the word that matches the word under the cursor, and stay on the first match that is not annotated
% find the other half of the bracket! !
yy copy the line where the cursor is
dd delete the line where the cursor is
D delete the current cursor to the end of the line
dG delete the current line to the end of the document
p Paste the content copied by yy
x delete the character under the cursor
u Undo the operation of the previous step
3yy copy the 3 lines where the cursor is located
5dd delete the 5 lines where the cursor is located
i
a
o
:q! Force quit
:wq! Force write exit
:set nu display line number
:The number is adjusted to the number line
Press esc at any time to exit the bottom line command mode
:! command Temporarily leave the vim command Mode, the result of executing command
For example:!ip a Temporarily look at the ip information, and then you can go back to vim
:set nu display vim line number
:set nonu cancel line number
How to move the cursor
h or the left arrow key (←) moves the cursor one character to the left
j or down arrow key (↓) to move the cursor down one character
k or up arrow key (↑) Move the cursor one character up
l or right arrow key (→) Move the cursor one character to the right
Move down 5 lines 5j
Move 10 characters to the right 10l
n(space) Press the number n, such as 10, and then press the space, the cursor will move 10 characters to the right