Basic operations
Edit File
Vim [Options] [file...]
Mode
Open the file and enter the normal mode of VIM. You can use various commands to operate the text.
Press the letter I to enter the insert mode. In this mode, all keyboard keys are normal characters and are inserted into the text. Press ESC to exit and enter Normal Mode
Press the letter V to enter visual mode. In this mode, you can select text and perform command operations. Press ESC to exit and enter Normal Mode
Press R to enter the modify mode. In this mode, you can modify the position of the cursor.
Insert mode
I ---- Insert at the cursor position
A --- Insert after the cursor
I --- insert at the beginning of the current row
A --- Insert at the end of the current file
O ---- insert in the next row of the current row
O --- Insert the last row of the current row
S ---- Delete the current character and insert it into the current character
S ---- delete current row insert
C [cursor Movement Operation Command] ---- Delete to the position after the cursor movement operation command and enter the insert status
Move the cursor (noraml Model)
H --> move the cursor left
J --> move the cursor down
K --> move the cursor up
L --> move the cursor right
W --> move the cursor to the beginning of the next word
E --> move the cursor to the end of the next word
0 --> move the cursor to the beginning of the line
$ --> Move the cursor to the end of the row
B --> move the cursor to the beginning of the previous word. If the cursor is not at the beginning of the current word, move the cursor to the beginning of the word.
Gg --> move the cursor to the beginning of the file
G ----- move the cursor to the end of the file
[Number] G --- move the cursor to the beginning of the row specified by [number]
[Number] % --- move the cursor to the beginning of the line in % [number]
+/---- Move the cursor to the beginning of the last line/previous line
Delete operation
X ------ Delete the character at the cursor position
DW ---- Delete the word where the cursor is located. If the cursor is in the middle of the word, delete the current position to the end of the word.
D0 ---- Delete the cursor position to open a fight in the row
D $ ---- Delete the cursor position to the end of the row
Dd ---- Delete this row
Undo/Redo
U ---- undo the previous operation
U ---- undo the bank to its initial state
CTRL-r undo the previous Undo operation/Redo
Modify
R ---- modify the character at which the current cursor is located
R --- enter the replace mode, which can be modified from the current position and exited by pressing ESC
CC --- Delete the row and enter the insert mode (modify the row content)
~ --- Change the current character's case sensitivity
Copy/paste
Copy: In normal mode, press V to enter visual mode, use the command to change the cursor position to operate the selected characters, and press y to copy the selected characters
Paste: Press P to paste the last copied content or the last deleted content after the cursor
P --- paste the copied content to the previous row of the row where the cursor is located
YW ---- copy the word at the cursor position
YY ---- copy the current row, no matter where the cursor is located
Save/exit
: W --- save
: Q --- exit
: WQ --- save and exit
: Q! --- Force exit, not save
: W [filename] --- save to a given file
Search/replace
% --- Locate matching brackets (parentheses, braces, braces]
/[Charaters] --- find the character specified by charaters
? /[Charaters] --- reverse query of the character specified by charater
N ---- repeat the last search
N --- repeat the last lookup and Reverse Lookup
: S/old/new ---- Replace the first match of the current row
: S/old/new/g --- replace all matching items of the current row
: #,# S/old/new/G ---- #, # Replace all matching items in the specified region for the row-ready Region
: % S/old/new/g ----- Replace the match in the entire file
: % S/old/new/GC ---- search for matching items in the entire file and prompt whether to replace
Several query commands
: Set IC ---- set case-insensitive during search
: Set noic ---- set the search process to be case sensitive
: Set HLS is ---- set the search result to be highlighted
: Noh [lsearch] ---- cancel display of search result height
Repeat the previous command
. ---- Repeat the previous command
Advanced Operations
Enter multiple identical characters at a time [number] [I, A, I, a] [charater] [ESC]
For example, 25i * ESC inserts 25 at the current cursor position *
Replace multiple characters [number] R [charater]
For example, replace "|" with "&" ---- 2R &
Quickly move the following row to the end of the row J
Vim uses zhibei ---- learning the VI and VIM editors