My notepad

Chris' IT notes…
← Back

Vim - Comment multi lines

First way:

v -> select whatever needs to be commented out :(appears this) :'<,'> add s/^/#(it will be now :'<,'>s/^/#) Press Enter

Second way:

For commenting out a block of text, do the following:

  1. hit CTRL + v (visual block mode)
  2. use the down arrow keys to select the lines you want (it won't highlight everything)
  3. Shift + i (capital I)
  4. insert the character/text you want to add at the beginning of the line (e.g. #)
  5. Press ESC.

To uncomment a block:

  1. Go the to first line of code where you want to start uncommenting from.
  2. Press 0 (To bring the cursor to the beginning of the line.)
  3. CTRL + v and select lines to be uncommented.
  4. x that will delete all the # characters vertically.

Source: https://www.quora.com/How-can-I-un-comment-a-block-of-text-in-Vim