DEV Community

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

Posted on • Edited on

3 1

(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!

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

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!

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay