VIM has 6 basic modes and 5 derivation modes.
Basic mode
Normal mode
Insert mode
Visual mode
Selection mode
Command-line mode
Ex Mode
Derived mode
Operator wait mode
Insert Normal Mode
Inserting visual mode
Insert Selection Mode
Replacement mode
1. Move the cursor (normal mode)
H: Left
J: Next
K: Up
L: Right
2. Insertion mode and method of exiting Vim
LS: Displays the file under the current path
vi+ FileName: Open the file, default into normal mode, you can use the arrow keys described in 1, press I, that is, enter the insertion mode (the bottom left corner can see the insert word).
Exit Insert mode: Press ESC to return to normal mode.
Various ways to enter insert mode:
Tap button |
meaning |
I |
Enter insert mode in front of cursor |
I |
Enter insert mode at the beginning of the line where the cursor is located |
A |
Enter insert mode after the cursor |
A |
Enter insert mode at the end of the line where the cursor is located |
O |
Inserts a blank line below the line of the cursor and enters insert mode |
O |
Inserts a blank line above the line of the cursor and enters insert mode |
S |
Removes the specified character from the cursor and enters insert mode |
S |
Clears the cursor line and enters insert mode |
Ways to exit Vim (multiple command line mode):
: q! : Force quit, do not modify
: Wq : Save Exit
3. Delete commands, digital secret, undo and Redo Commands
Delete command
1. In normal mode, deleting a single character can be used with the X command
2. Delete More characters can use the D command (delete), using the method: D+motion
motion--an instruction that represents the scope of operation
Key |
meaning |
0 |
Position the cursor at the beginning of the line |
^ |
Ditto |
$ |
Move the cursor to the position of the row bit |
B |
Position the cursor at the beginning of the word where the cursor is located |
E |
Position the cursor at the end of the word where the cursor is located |
W |
Position the cursor at the beginning of the next word |
Gg |
Position the cursor at the beginning of the file |
G |
Position the cursor at the end of the file |
Key |
meaning |
D0 |
Removes all characters from the current position (not included) to the beginning of the line |
d^ |
Ditto |
d$ |
Delete all characters from the current position of the cursor (not included) to the end of the line |
Db |
Delete all characters from the current position of the cursor (not included) to the beginning of the word |
De |
Remove all characters from the cursor's current position (contained) to the end of the word |
Dw |
Removes all characters from the current position (contained) to the beginning of the next word |
Dh |
Remove one character from the front of the cursor |
Dl |
Delete the character specified by the cursor |
Dj |
Remove all characters from the row and the next line of the cursor |
Dk |
Remove all characters from the row and previous line of the cursor |
Dd |
Remove all characters from the line where the cursor is located |
DGG |
Delete all characters from the line to the beginning of the file |
Dg |
Delete all characters from the line to the end of the file |
The Secret of Numbers
1. Digital +motion: Repeating multiple motion
2.d+ Digital +motion: Deleting multiple motion Ranges
Revoke
1.u means undo last modification
2.U means undo modification of the entire row
3.commend+r shortcut keys to restore undone content
4. All deletions are not really deleted, but are stored in a buffer of vim, equivalent to the clipping function
4. Paste command, replace command, replace mode and modify command
-
paste command
-
use the delete command under VIM and do not delete your things directly, Instead, it is placed in a vim register.
-
use the P command to paste the last deleted content after the cursor (large The write p can be pasted before the cursor)
-
Note:
-
if you pasted an entire line, the P command will be pasted on the next line of the cursor
-
If you paste a local string, the P command starts pasting after the cursor
Copy command
Replace command
The r command replaces the character of the cursor by first moving the cursor to the character that needs to be replaced, pressing the R key, and then entering the new character
Enter a number before you type the R command, indicating that multiple characters are uniformly replaced with new characters starting at the cursor
The r command goes directly into the replacement mode
Modify command
modifications and substitutions are not the same , the modification goes into insert mode, and the substitution does not enter insert mode
Vim with C command implementation modification: c[digital]motion
5. File information, jumps, positioning brackets, and indents
6. Search command and Replace command
/target
|
? target |
search direction |
start backward from the cursor |
start with the cursor forward |
n |
Search Backward Next |
forward search next |
N |
search forward next |
search Backward next |
-
Ten special characters
Replace command
: s/old/new
: s/old/new/g
:%s/old/new/g
:%S/OLD/NEW/GC
: 5,13s/old/new/g
7. Execute shell commands, save files as, merge files, and open multiple files
Execute shell command
Save File as
Save local content as
1. Enter the visual mode
2.:w file name
Merging files
Open multiple Files
-O Vertical Side-by
-O Horizontal Side-by
Use CONTROL+W+W to switch the cursor to the next file
For vertically-side files: Use the control+w+ up/down direction
For horizontally-side files: Use control+w+ around direction
: QA Exits All Files
: WQA Save All changes
: qa! Ignore All modifications
Vim Operation Guide