Linux-vim, the most common operation, linuxvim
1. Open a file
Vim + #: open the file and locate it in line #
Vim +: open the file and navigate to the last line.
Vim +/PATTERN: open the file and locate the first line of the line matched by PATTERN for the first time.
Ii. Close files
: Q exit
: Wq: Save and exit zz in the editing mode equal to: x
: Q! Force exit without saving
: W save
: W! Force save
Iii. Mode Conversion
Edit mode-> input mode
I: Switch to input mode before the character of the current cursor
A: After the character of the current cursor, convert it to the input mode.
O: at the bottom of the row where the current cursor is located, create a new row and convert it to the input mode.
I: Switch to input mode at the beginning of the row where the current cursor is located
A: At the end of the row where the current cursor is located, convert it to the input mode.
O: Create a new row above the row where the current cursor is located and convert it to the input mode.
Input mode-> edit mode
ESC
Edit mode-> last line mode
:
Last line mode-> edit mode
ESC
Edit mode-> visual mode
In visual mode, you can freely select the selected content from the cursor position, and then delete or copy the selected content.
4. move the cursor (editing mode)
1. move by character
H, j, k, l: Left, bottom, top, right
2. Move in words
W: Jump to the beginning of the next word
E: jump to the end of the current or next word
B: Jump to the beginning of the current or previous word
3. In-row jump
0: Beginning of the absolute line
^: The first non-blank character at the beginning of the line
$: End of the absolute line
4. jump between lines
# G: Jump to row # in the last line mode: # Just give the row number directly.
G: when the last line is equal to the last line: $
5. Screen flip
Ctrl + d: Flip down half screen
Ctrl + u: half screen up
Ctrl + f: Flip the screen up
Ctrl + B: Flip down the screen
6. Delete
1. delete a single character
X: delete a single character at the cursor
2. Combined use of the d command and the jump command
Dw, de, db delete a word after/before the current cursor
Dd: deletes the row where the current cursor is located.
# Dd: Delete the rows that contain the current cursor
7. copy and paste
1. Copy y to use the same command as d.
2. paste p or P
8. Replacement
R #: Replace the current character #
R: Replacement Mode
9. unedit
U: undo the previous edit operation. You can undo the continuous u command
Ctrl + r: undo the last undo
10. Repeat the previous edit operation
.
11. search and replace
/PATTERN: Search for PATTERN from the beginning of the cursor to the end of the file
? PATTERN: Search for PATTERN from the beginning of the cursor
N: Repeat the previous search command in the same direction.
N: Repeat the previous search command in the reverse direction.
: S/p1/p2/g replace all p1 in the current row with p2
: N1, n2s/p1/p2/g replace all p1 from n1 to n2 with p2
: % S/p1/p2/g replace all p1 in the file with p2