Jeff Roberts
RHCE #804006066322833
Vim-Fu is now iPhone and Android friendly

Check out the Vim-Fu Store!

Vim-Fu

commenting out multiple lines in vim

Visual block mode is a great tool when commenting out a section of code, large or small, all at once.

Look at this section of code from a script I am writing. Let’s say I wanted to comment out everything you see.

vb_mode_11

I start with my cursor on the “%” and enter visual block mode by typing {CTRL}-v , then move the cursor down to the last line I want to comment out.

vb_mode_2

Then type “I” to insert in front of the slected text (“i” would insert after, and that’s not what we want) and then the “#” character to comment the first lineout.

vb_mode_31

Once you have the first line commented it’s time for the magic. Hit ESC to let Vim know you are done editing, and it will apply your edit to all the selected lines!

vb_mode_4

This is a HUGE time saver!

3 comments to commenting out multiple lines in vim

  • richeek

    gr8 tip…saved a lot of time! Thanks

  • jroberts

    Alexy,

    YES, vim can do what you are asking. Do what I show in the above example but when you get to the last line, before you hit “esc”, hit “$” to select the end of all lines.

    Thanks for posting your question.

    Jeff

  • Alexey Moseyev

    Jeff
    how to select multiple lines (full length) in vim in visual mode when last line is shorter than others?
    looks like by default vim using block selection (wrap selection is disabled)

    Thanks
    Alex.

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>