I have heard the following jokes about VIM:
The best way to randomly generate a string is to get the novice out of the Vim editor.
It can be seen that people who have just touched vim are uncomfortable with the use of vim, but because in the world of Linux, Vim often exists as a built-in text editor.
Therefore, editing files in a non-desktop environment requires you to be familiar with vim so that you can do your daily work with ease.
Three modes of editing
Vim is a modified version of VI, here do not make a distinction, unified with vim instead of VI.
- General mode
Use the following command:
This opens a file mode is a general mode, the mode can use the next key to move the cursor, delete, copy and paste characters or lines, etc., but not __ can insert __ new characters.
- Edit mode
You cannot edit the contents of a file in normal mode. You can enter edit mode by pressing the following key in normal mode:
- I,I:I is inserted at the current cursor, and I is inserted for the first non-empty characters of the current line; (similar to Home + I)
- A,A:A is inserted for the next character of the current cursor, and a is inserted for the last character of the current line; (similar to end + i)
- R,R: Enter replace mode, R replaces only the character of the cursor once, and R is always replaced until the ESC key is pressed;
So many buttons to enter the editing mode, commonly used is __i and a,a__.
- Command-line mode
General mode into the command line mode, enter:? /three characters to enter.
This mode is very rich in features, providing data search, replacement, file saving, display line number and other text editor advanced features.
As shown: press:, enter the command Wq to save the current changes and exit the editor.
Common shortcut keys
Common keys in general mode:
- Cursor movement
- 0 or home: The cursor moves to the beginning of the current line;
- $ or end: The cursor moves to the end of the current line;
- G: The last line of the moved file; (common)
- Ng:n is a number that moves to the nth line of the file, such as 20G to the 20th line of the file;
- GG: Move to the first line of the file. Equivalent to 1G (common)
- J: Delete the line with the cursor and the next row of data, similar to the deletion of the bank \ r \ n
- U: Undo last Action; (undo)
- Ctr+r: Redo the last operation, reverse undo; (Redo)
- .: Repeat last action, repeat delete, repeat paste, etc.;
- Delete, copy, and paste
- X,x:x for the backward deletion of a character similar to del,x for the former deletion of similar backspace;
- NX: Post-delete n characters
- DD: Delete When moving forward
- NDD: Deletes the current line and subsequent totals n rows
- D1G: Removes all characters from the line to the first line of the cursor
- DG: Remove all characters from the line to the last row of the cursor
- d$: Delete the character between the end of the line of the current line and the cursor
- Yy:y is copied, with the deletion;
- P,p:p is to paste the copied content again at the next line of the cursor, and P is to start pasting on the previous line of the cursor.
- /pattern: Enter command mode, enter the regular pattern of the lookup, and look down to the next pattern-compliant string.
- Patterb: Search upward for pattern-compliant strings;
- N: Repeat the previous find operation in the same direction, next;
- N: Repeat the previous find operation in the opposite direction
- : n1,n2s/w1/w2/g between N1 and N2, looking for W1 and replacing them with W2.
- : N1,N2S/W1/W2/GC between N1 and N2 line, looking for W1, replacing with W2, need to ask the user before replacing;
- : 0, $s/p/p/gc
VIM Basic operation