How to use NERD Commenter for vim -- how to use <Leader> key
Solution 1:
Try the built-in help, it's excellent. :help <Leader>
brings you to the relevant documentation. It's just an identifier for an unused key (by default \, but many change it to ,) that is recommended for starting any custom mappings.
NERD_commenter defines the <Leader>cc
mapping, so you'd press (one after the other): \ C C.
Solution 2:
Your keyboard is the problem
On many non-English keyboard layouts, the backslash \
is only accessible through an AltGr key combination. This makes the default setting of the <Leader>
character rather impractical for these non-English keyboard users.
Moreover, <Leader>
key combinations are subject to a default 1000ms time-out. This can be observed by the disappearance of the <Leader>
key at the right edge of the command line.
So, non-English keyboard users need to be real quick typists for </kbd>cc to work. Failure to do so, results in an undesired cc
line change.
Here is an example of a German keyboard layout with the backslash-bearing key on the top row, third from right:
#Solution
Non-English keyboard users are advised to change the <Leader>
key from the \
character to the more accessible , key. Vim beginners should also consider a slightly longer 1500ms time-out. Here is what needs to be added to ~/.vimrc
let mapleader=","
set timeout timeoutlen=1500
One final caveat; these changes only take effect after completely exiting Vim. Resourcing with :source $MYVIMRC
will not work!
Done that, one can now use ,cc for commenting with NERD Commenter.
Solution 3:
how do I go about commenting lines with /* */?
Аs is stated in the documentation:
[count]<leader>cm |NERDComMinimalComment|
Comments the given lines using only one set of multipart delimiters.
So, just use
-
\ c m (if your
<leader>
is \), or -
, c m (if your
<leader>
is ,)
Solution 4:
@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.