vim mode:
Normal mode (press Esc or Ctrl+[ to enter) The lower left corner displays the file name or is empty
Edit mode (press i or a key to enter) The lower left corner displays --INSERT--
Visual mode (don't know how to enter) The bottom left corner shows --VISUAL--
Common commands inside vim (the following commands, except 2, editing commands, the rest are directly input commands in normal mode):
1. Find: "/" + find content
2. Edit: Press a, then start adding
3, delete: delete line: dd
4. Replace:
:s/old/new/ : replace new with old, replace the first match of the current line (the cursor must be moved to that line first)
:s/old/new/g : replace new with old, replace all matches on the current line (the cursor must be moved to that line first)
:%s/old/new/ : replace new with old, replace the first match of all lines
:%s/old/new/g : replace new with old, replace all matches in the whole file
:10,20 s/^/ /g : Add four spaces before each line from line 10 to line 20 for indentation.
5. Cancellation: u
6. Copy and paste: yy copies the current line, p: If the yy command was used to copy a line, then paste it on the next line of the current line
7. Cut: Press v to start, then move the cursor, and then press d to end, you can cut a desired string; press p to paste
8. Notes:
Comment out a single line: # sign
Commenting multiple lines is actually using the substitution method, adding a # sign at the beginning of the line. The following is an example:
:3,5 s/^/#/g : comment lines 3-5
:3,5 s/^#//g : uncomment lines 3-5
:1,$ s/^/#/g : Comment the entire document.
:%s/^/#/g : Comment the entire document, this method is faster.
9. Exit:
Save and exit: ":wq"
Exit without saving: ":q!"
10. Other skills usage:
Delete: Click Esc twice, then enter 1000, (representing rows 0-1000), and then click the d key twice to delete rows 0-1000.
Arrange the pasted text neatly: Esc click twice, then enter: gg=G, done!