After entering the vi command, you enter the full-screen editing environment, and the state at this time is 命令模式. In the command mode, enter some commands, but when you click the corresponding key on the keyboard to enter the commands, these commands will show the final effect, and the command characters will not be displayed on the editor interface.
1. Basic operation of vim editor
Subcommand name
effect
i
Edit the document and display it in the status line – INSERT
w
Save the edited document
q
Exit to close document
q!
Force close document exit
/ String
Find the specified string in the document
set no
The line number is displayed in the document
set nonu
Line numbers are not displayed in the document
d
Delete the current line
nd
Delete from current line to n lines
n1, n2d
Delete line n1 to line n2
s / string1 / string2 / g
Replace string 1 with string 2 in the document
ESC
Exit document editing state and enter non-editing state
in
In the non-editing state, undo the last operation
2. Quick jump in the line
Operation keys
Features
^
Quickly jump the cursor to the first character of the line home
$
Quickly jump to the end of the line
w
Quickly jump the cursor to the first letter of the next word at the current cursor position
b
Quickly jump the cursor to the first letter of the previous word at the current cursor position
e
Quickly jump the cursor to the last letter of the next word at the current cursor position
Arrow keys
Move the cursor up, down, left, and right
Home
Quickly position the cursor to the beginning of the line
End
Quickly position the cursor to the end of the line
3. Quick jump between lines
command
Features
: set no
Show line number in editor
:set nonu
Cancel line number display in the editor
1G
Jump to the first line of the file
G
Jump to the end of the file
#G
Jump to line # of the file
PageUp
Page up text
PageDown
Page down
Second, the deletion and revocation of vim editor
1. Deletion of file content
command
Features
x
Delete a single character at the cursor = delete
dd
Delete the line where the cursor is located ndd can delete 5 lines of content
dw
Delete all characters from the current character to the end of the word (including spaces)
of
Delete all characters from the current character to the end of the word (excluding spaces at the end of the word)