When we have time at work, we encounter the need to add comments to the configuration file in batches. If adding line by line is time-consuming and laborious, we can use the visualization mode of the vim editor to quickly add comments in batches .
I use the /etc/passwd file as an example to demonstrate quickly add comments at the beginning of the line
Open the file like this:
I need to quickly add the comment symbol # on lines 30-35, first press Esc and then Ctrl+v to enter the visual block mode
Locate to the beginning of line 30 and use the arrow keys to go down to line 35
At this time, the selected place will have a shadow, and then press the uppercase I (read i) to enter the insert mode
Insert the # symbol at the cursor position
Then press Esc, 30-35 will all add comment symbols
So what do we do if we want to delete comments in batches? It’s also very simple. We still use this method.
First Ctrl+v to enter the visual mode, the arrow keys to select all the annotation symbols to be deleted, and then press the delete key.
Isn’t it very simple? After more practice and proficiency, work efficiency can be greatly mentioned~
If you want to add other characters in batches, you can also use this method.