Commenting multiple lines
- Move the cursor to the start line of the comment.
- Press
ESCto enter insert mode. - Press
ctrl+vto enter visual block mode. - Use up and down arrows or
shift+]to select the lines you want to comment on. - Press
shift + Ito enter insert mode. - Enter the comment character i.e.
#. - Press
ESCthenESC(ESC twice).
Uncommenting multiple lines
- Move the cursor to the start line to uncomment.
- Press
ESCto enter insert mode. - Press
ctrl+vto enter visual block mode. - Use up and down arrows or
shift+]to select the lines you want to uncomment. - Press
XorDto delete the comment character.
Happy hacking on VIM!
Top comments (1)
If you aren't opposed to a plugin, I really like
vim-commentaryby 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
gccto toggle the comment on a single line, and to do multiple you can select them in visual mode as above, and gogcto either comment or uncomment the lines!