Tip #1316: Easy visual commenting - Navigating visual selections with '< and '>
| tip karma
Rating 5/2, Viewed by 1369
Read and edit this tip on the
Vim tip wiki.
The wiki may have a more recent version of this tip.
||August 24, 2006 19:44
||as of Vim:
By using '< and '>, you can jump to the start and end, respectively, of the most recent visual selection. This is a great and simple way to comment out a block of visually selected code:
vmap ,/ '><ESC>o*/<ESC>'<O/*<ESC>
This works because even after you <ESC> out of visual mode, '< and '> (presumably) remember where the most recent visual selection began and ended. Actually, this doesn't always work. Curly braces seem to confuse Vim when I do it that way, so here's an alternate way with marks (note: this will overwrite mark ')
vmap ,/ '<m''><ESC>o*/<ESC>''O/*<ESC>
Now, uncommenting is as easy as deleting the two lines that the /* */s are on. Or you can use this: (note: this will produce unexpected results if your /* */s aren't on their own lines!)
vmap ,u ?\/*dd/*\/dd:nohl<CR>
<< netrw x command |
Open a buffer in its own tabpage >>