Vim – Commenting out multiple lines

There are two ways to do this without a vim plugin:

  1. Select your lines with VISUAL BLOCK (CTRL-V), then press I to insert before all highlighted lines. Next type your comment character (#, ;, depending on the language), then press ESC twice.
  2. Select your lines with VISUAL LINE (SHIFT-V) then type:

In other words, substitute the selected start of lines with the # character.

Leave a Reply

Your email address will not be published.