First, open the file
Vim +#: Open the file and locate it on line #
Vim +: Open the file and navigate to the last line
Vim +/pattern: Open the file and navigate to the beginning of the line that was first matched by PATTERN
Second, close the file
: Q exit
: Wq Save and exit equals: X equals edit mode ZZ
: q! Do not save forced exit
: W Save
: w! Forcibly saved
Three, Mode conversion
Edit mode, Input mode
I: Switch to input mode before the current cursor character
A: After the current cursor character, switch to input mode
O: Create a new row below the current cursor line and switch to input mode
I: Switch to input mode at the beginning of the line where the cursor is currently located
A: At the end of the line where the current cursor is located, switch to input mode
O: Create a new row above the current cursor line and switch to input mode
Input mode, edit mode
Esc
Edit Mode--last-row mode
:
Last-line mode, edit mode
Esc
Edit mode, visual mode
V Visual mode can be freely selected from the cursor position, and then the selection of the content to delete, copy and other operations
Four, move the cursor (edit mode)
1, character-by-word movement
H,j,k,l: Left, bottom, top, right
2. Move in Word units
W: Jump to the beginning of the next word
E: Jumps to the ending of the current or next word
B: Jump to the beginning of the current or previous word
3, in-line jump
0: The absolute beginning
^: first non-whitespace character at the beginning of a line
$: absolute end of line
4. Jump between rows
#G: Jump To Line # equals the last line mode: # directly to the travel number
G: Jumps to the last line equal to the final row mode: $
Five, flip screen
CTRL + D: Flip down half screen
CTRL + U: Flip up half screen
CTRL + F: Turn up one screen
CTRL + B: Flip one screen down
Vi. deletion of
1. Delete a single character
X: Delete a single character at the cursor location
2, D command combined with jump command
Dw,de,db Delete a word after/before the current cursor
DD: Delete the line where the current cursor is located
#dd: Delete the # line including the line where the current cursor is located
Vii. Copy and paste
1. Copy y usage with d command
2. Paste P or P
Eight, replace
R #: Replace the current character with #
R: Replacement mode
Ix. Revocation of editing
U: Undo the previous edit operation, the continuous u command can be reversed straight ahead
CTRL + R: Undo Last Undo
Ten, repeat the previous edit operation
.
Xi. Find and replace
/pattern: Searches for PATTERN at the end of the file from the beginning of the cursor
? Pattern: Searches for pattern from the beginning of the cursor to the top of the file
N: Repeat the last search command in the same direction
N: Repeats the last search command in the opposite direction
S/p1/p2/g: All P1 in the current row are replaced with P2
: N1,n2s/p1/p2/g replaces all P1 in N1 to N2 with P2.
:%s/p1/p2/g replaces all P1 in the file with P2
Linux--vim the most common operations