Commenting multiple lines
- Move the cursor to the start line of the comment.
- Press
ESC
to enter insert mode. - Press
ctrl+v
to enter visual block mode. - Use up and down arrows or
shift+]
to select the lines you want to comment on. - Press
shift + I
to enter insert mode. - Enter the comment character i.e.
#
. - Press
ESC
thenESC
(ESC twice).
Uncommenting multiple lines
- Move the cursor to the start line to uncomment.
- Press
ESC
to enter insert mode. - Press
ctrl+v
to enter visual block mode. - Use up and down arrows or
shift+]
to select the lines you want to uncomment. - Press
X
orD
to delete the comment character.
Happy hacking on VIM!
Top comments (1)
If you aren't opposed to a plugin, I really like
vim-commentary
by tpope, for this! Its language aware so it can use the correct comment for the correct language!github.com/tpope/vim-commentary
With this installed you can do
gcc
to toggle the comment on a single line, and to do multiple you can select them in visual mode as above, and gogc
to either comment or uncomment the lines!