- Global substitution
Format:
":%s/to replace character/replace with new character/g"
:%s/old/new/g
Specify line substitution
Format: ": Starting line, terminating line s/to replace character/replace with new character/g"
: 1,5 s/old/new/g
- Multi-file replacement
For multiple file replacements, such as replacing All. c files with A_value as B_value, you can use the following methods:
VI *.c
: Argdo%s/a_value/b_value/ge | Update
Where update is a direct replacement overwrite the original file, if you need to confirm, you can use
: Argdo%s/a_value/b_value/gec | Update
- Multi-line Comments:
First press ESC to enter command line mode, press Ctrl + V to enter the column (also known as block) mode;
Use the upper and lower keys at the beginning of the line to select multiple lines to comment;
Press the keyboard (uppercase) "I" key to enter the insertion mode;
Then enter the comment symbol ("//", "#", etc.);
Finally, press the "ESC" key.
Note: After pressing the ESC key, will wait a moment to appear the comment , do not worry ~ ~ Time is very short
- To delete multiple lines of comment:
First press ESC to enter command line mode, press Ctrl + V to enter the column mode;
Select multiple lines to uncomment;
Press "X" or "D".
Note: If it is a "//" comment, it needs to be done twice, if it is a "#" comment, once
- Delete multiple characters at the beginning of a line
First press ESC to enter command line mode, press Ctrl + V, enter the column mode, press "right arrow" to select the length of the character to delete;
Press the DOWN arrow to select how many rows to delete
Press "D" to delete
- Other
Display line number: Set Nu
To suppress line numbers: Set Nonu
Back to end of sentence: Shift + $
Back to the first sentence: Shift + ^
Segment Header: {
Kenu:}
Previous modification: G,
Post-amendment: g;
Delete the remaining part of the word after the cursor: DW
Delete the remaining part of the line after the cursor: d$
Merge the next line to the end of the current line: J
Vim Advanced editing Tips