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.
May 13, 2008 at 6:46 am |
[…] VIM – Comment blocks of code « Not So Frequently Asked Questions […]
May 19, 2009 at 10:20 am |
Capital “I” puts me simply into an insert mode.
January 1, 2010 at 7:09 pm |
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).
October 6, 2009 at 6:06 am |
[…] 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); })(); […]
October 21, 2010 at 11:19 am |
So… What’s an easy way to UNcomment it? Or should I go the script route? (Found several.)
December 7, 2010 at 10:56 am |
James: it’s even easier than commenting stuff out: You use CTRL-v to block mark just the comment characters (which is easy, they are in equal amounts at line beginnings), than just press d to delete the block of text. And it is as if you never commented anything out 😉
May 21, 2012 at 11:58 am |
Nice tip.
July 8, 2012 at 1:42 am |
[…] VIM – Comment blocks of code « Not So Frequently Asked QuestionsA special comment block is a C or C++ style comment block with some additional markings, so doxygen knows it is a piece of structured text that needs to end up … […]
January 24, 2013 at 12:05 pm |
good one!
April 3, 2013 at 1:50 pm |
[…] https://notfaq.wordpress.com/2006/07/28/vim-comment-blocks-of-code/ […]
May 17, 2013 at 3:52 am |
Reblogged this on Sven Logan's Blog and commented:
Proved to be quite useful when editing system configuration files (Apache2, etc.). Thanks!
September 3, 2013 at 7:47 am |
[…] Vim copy and past commands – Setting blocks, yank, paste, cut, etc.. in vim […]
November 30, 2014 at 8:32 am |
[…] I just found this one today via NSFAQ: […]
December 6, 2014 at 11:16 am |
[…] I just found this one today via NSFAQ: […]
December 10, 2014 at 1:35 am |
[…] I just found this one today via NSFAQ: […]
March 11, 2015 at 7:33 pm |
Reblogged this on Darren Goossens and commented:
I need to remember this and I never do.
January 1, 2016 at 4:05 pm |
[…] I just found this one today via NSFAQ: […]