I am using NERD commenter
Let's say that I want to comment out lines from 78 to 172. This is what I do. I calculate the difference. That is 94. put my cursor on line 78 and then I do: 94 , c space
In this way I comment 94 lines starting from line number 78.
I don't like the calculation that I need to do. I was hoping to pass a range something like
78,172 to comment the code from line 78 to 172. Am I missing something.
Looking at the popularity of this plugin, it seems there must be a better way to comment and uncomment.
The leading characters // are added to the beginning of each line when commenting one or more lines of code. You can also block comment multiple lines of code using the characters /* */ .
@IngoKarkatNote: You don't need to hold down the key, just press it like any other key, and release it. Completely the wrong advice for the original question! With NerdCommenter, you DO have to hold down the <leader> key. Otherwise, as OP found, you just end up activating 'change' mode instead.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With