Ozkan
Ozkan

Reputation: 4170

I Can't work with NERDCommenter

I installed NerdCommenter like how it should be installed. And I read the help files. So, for commenting a line I need to do <leader>c$.

I also read that the leader key is \ by default. But it didn't work for me. I never used the leader key so I think I am doing something wrong.

Can anybody help me for using the basic commenting and uncommenting selected lines using nerdcommenter?

Upvotes: 3

Views: 3083

Answers (2)

Serge Stroobandt
Serge Stroobandt

Reputation: 31618

Problem

On many non-English keyboards, the backslash \ is only accessible through a AltGr key combination. This makes the default setting of the <Leader> character rather impractical for these 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 \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: German keyboard layout

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!

Now, one can use ,cc for commenting with NERD Commenter.

Upvotes: 10

Rene Wooller
Rene Wooller

Reputation: 1147

I had the same problem, and I was noticing that it wouldn't flat out deny the command, but would say "No Error" and just not do anything. I read the install instructions for NERDCommenter very carefully and noticed this bit:

After the 'Classic' or 'Pathogen' install, make sure that you have filetype plugins enabled, as the script makes use of |'commentstring'| where possible (which is usually set in a filetype plugin). See |filetype-plugin-on| for details, but basically, stick this in your vimrc:

filetype plugin on

Even though I'd used NeoBundle rather than Pathogen, I tried that, and after a restart, voila. Hope it helps.

Upvotes: 1

Related Questions