Vim uses
1. The four modes of Vim
Vim is a multi-mode editor, mainly including command mode, edit mode, bottom line mode and replacement mode. The relationship between the four modes is as follows:
- Shift+: Enter the bottom row mode.
- i: Enter edit mode under the current cursor.
- a: The cursor jumps backward one step to enter the editing mode.
- o: The cursor changes to a new line and enters the edit mode.
- Shift+r enters replace mode.
Note : Except for the command mode, the other three modes are all converted in the command mode + command, and it
is only necessary to switch to the command mode without brain Esc.
Second, command mode
1, copy, cut, paste
- yy/nyy: copy the current line or copy n lines including the current line
- p/np: Paste once or multiple times under the current cursor
In the command mode, use the yy command to copy the line where the cursor is located, and use the np command to paste.
- dd/ndd: Cut the current line or n lines including the current line.
Note : If only dd/ndd operation is performed without p/npp (paste) operation, then this command is equivalent to delete.
2. Undo operation
- u: Undo the last operation.
- Ctrl+r: Undo the u operation.
3. Cursor movement
- Shift+g: Move the cursor to the end of the document.
- gg: Move the cursor to the beginning of the document.
- n+Shift+g: Move the cursor to the specified line.
Cursor current line:
10+Shift+g:
- Shift+4 ($): Move the cursor to the end of the document line.
- Shift+6 (^): Move the cursor to the beginning of the document line.
- w/nw: Move the cursor backward within the line in units of one or more words.
- b/nb: Move the cursor forward within the line in units of one or more words.
4. Replace, select, delete
- Shift+~ / nShift+~ : Switch between upper and lower case.
- r/nr: Replace the character where the current cursor is located or multiple characters including the current cursor.
- x/nx: Inline deletion, left -> right.
- X/nX: Inline deletion, right -> left.
- v/nv: Select one or more characters in the line.
- d/nd: cooperate with the left and right keys to delete one or more characters or delete the selected characters.
5. Use of hjkl key
In the use of Vim, not only the up, down, left, and right arrows can move the cursor up, down, left, and right,
h: move the cursor to the left
j: move the cursor down
k: move the cursor up to drive
l: move the cursor to the right
6. Multi-line comment, go to multi-line comment
The method of multi-line comment:
① Press "Esc" to enter the command line mode
② Press "Ctrl + v" to enter the visual block mode
③ Use the up, down, left and right keys to adjust the number of lines to be commented and the width of the line
④ Then press "Shift + i" to enter Insert mode
⑤ Enter comment symbols, such as: "#", "//"
⑥ Press "Esc" again to complete multi-line comments [must remember this step~]
To remove multi-line comments:
① Press "Esc" to enter the command line mode
② Press "Ctrl + v" to enter the visual block mode
③ Use the up, down, left, and right keys to adjust the number of lines to be commented and the width of the line
④ Press d to complete the comment
Three, edit mode
Fourth, the bottom line mode
-
set nu: Display the number of rows.
-
set/nonu: Do not display the number of lines.
-
/key: key means that the content to be searched will be highlighted.
-
! Instructions (execute the basic commands of the Linux environment in the bottom line mode of Vim)
-
vs file: multi-window editing
-
Ctrl+ww: Switch the cursor to the window
-
%s///g: replace the content
-
w: Save the current document.
-
q: Quit the current document.
-
wq: Save and exit the current document.
-
Add after w or q! Represents Force Save or Force Quit.
Five, replacement mode
After Shift+r enters the replacement mode, you can replace the original characters at will.
Six, Vim configuration
The configuration of Vim is to touch a .vimrc configuration file and add the commands you want to configure in it.
For example: adding set nu to it is to display the number of lines in the document.
More detailed configuration can be found online.