NERD commenter : How to comment out a range
I'd do (in visual mode) :78v172G
to select and highlight lines 78 to 172, then just ,c<space>
.
It doesn't appear that NERDCommenter supports ranges, so Alex's answer would be correct, but he has a typo - it should be 78GV172G
to select (note - no preceeding :
), followed by your comment function ( in my case \cc
).
Enter Visual mode <ctrl> + V
, using your arrow keys, highlight the lines you want then /c<space>
(perhaps you have another key binded for commenting).
Sexy C comments mode
Ranges of lines just work by default with visual selection + <leader>cc
, tested on 2.5.2, as mentioned at: https://stackoverflow.com/a/1375070/895245
But above all, I want to highlight in this answer the "sexy mode" comments with <leader>cs
, which generates nice C multiline comments.
For example, if you start with:
This is a c style sexy comment
So there!
then <leader>cs
from visual selection transforms it into:
/* This is a c style sexy comment
* So there! */
And you can also switch to non-compact mode by adding to your .vimrc
:
let g:NERDCompactSexyComs = 0
which works as follows:
------------------------------------------------------------------------------
*'NERDCompactSexyComs'*
Values: 0 or 1.
Default 0.
Some people may want their sexy comments to be like this: >
/* Hi There!
* This is a sexy comment
* in c */
<
As opposed to like this: >
/*
* Hi There!
* This is a sexy comment
* in c
*/
Another related format which might be of interest is the "Minimal comment map" accessible with <leader>cm
and which produces:
/* Hi There!
This is a sexy comment
in C */
I wasn't able to find my preferred style unfortunately:
/* Hi There!
* This is a sexy comment
* in c
*/
so I opened: https://github.com/scrooloose/nerdcommenter/issues/379