Method Piece Selection Mode
Insert Comment:
Enter virtual mode with V
Use the up and down keys to select the number of lines you want to comment
Press CTRL + V to enter column mode
Press Capital I into insert mode, enter the comment ' # ' or '//', then press ESC two
Cancel Comment
Ctrl + V Enter block selection mode, select the comment symbol for the beginning of the line you want to delete, note//To select two, then press D to delete the comment
Method Two replace command
Bulk Comment:
Use the following command to add comments at the beginning of the specified line:
: Starting line number, ending line number s/^/comment/g
Uncomment:
: Starting line number, ending line number s/^ comment//g
Example Demo:
Add//comment on line 27-30
: 27,30s#^#//#g
Delete//comment on line 27-30
: 27,30s#^//# #g
Add # comments To line 10-20
: 10,20s/^/#/g
Delete # comments on line 10-20
: 10,20s/^/#/g
Note that in the example, the delimiter used is the opposite symbol, and if the match//is used #作分隔符这样不需要对/as Escape, save the number of inputs.
Vim bulk Comment and cancel bulk comment (GO)