VIM – Comment blocks of code

By Radu Cornea

Mark the area which is to be commented using the *blockwise* visual mode (CTRL-V, in Windows this is CTRL-Q).

Press I (capital i) and write the text you want to prepend to each line of the selected block, e.g. %.

Then press ESC and the text will be inserted to the left of each line of the selected block.

4 Responses to “VIM – Comment blocks of code”

  1. Linux T&T : VIM - Comment blocks of code Says:

    [...] VIM – Comment blocks of code « Not So Frequently Asked Questions [...]

  2. ivanatora Says:

    Capital “I” puts me simply into an insert mode.

    • michalmolhanec Says:

      That’s OK. Just type something, don’t worry that it will display just on the beginning of one line, when you press Esc, it will be added to all of the selected lines (some version of vim needs to press e.g. move key after Esc to display it).

  3. gvim – comentar múltiplas linhas : Wilson Blogue Says:

    [...] Via var linkwithin_site_id = 38479; (function () { var elem = document.createElement('script'); elem.type = 'text/javascript'; elem.src = 'http://www.linkwithin.com/widget.js?rand=' + Math.random(); document.getElementsByTagName('head')[0].appendChild(elem); })(); [...]

Leave a Reply

You must be logged in to post a comment.