DEV Community

Cover image for (Un)Commenting Multiple Lines
Musale Martin
Musale Martin

Posted on • Updated on

(Un)Commenting Multiple Lines

Commenting multiple lines

  1. Move the cursor to the start line of the comment.
  2. Press ESC to enter insert mode.
  3. Press ctrl+v to enter visual block mode.
  4. Use up and down arrows or shift+] to select the lines you want to comment on.
  5. Press shift + I to enter insert mode.
  6. Enter the comment character i.e. #.
  7. Press ESC then ESC (ESC twice).

Uncommenting multiple lines

  1. Move the cursor to the start line to uncomment.
  2. Press ESC to enter insert mode.
  3. Press ctrl+v to enter visual block mode.
  4. Use up and down arrows or shift+] to select the lines you want to uncomment.
  5. Press X or D to delete the comment character.

Happy hacking on VIM!

Top comments (1)

Collapse
 
coreyja profile image
Corey Alexander

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 go gc to either comment or uncomment the lines!