Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim and GVim: leader key not working

Tags:

vim

I have some plugins installed, including NERDCommenter and NERDTree. I can't get the leader key to work right for them, though. These are the default configs when I type :map

v  \c<Space>     <Plug>NERDCommenterToggle
n  \c<Space>     <Plug>NERDCommenterToggle
v  \cc           <Plug>NERDCommenterComment
n  \cc           <Plug>NERDCommenterComment

\c<space> just works like hitting c<space>. I've tried remapping the leader key with the following in my .vimrc in my home directory:

let mapleader = ","

This is reflected when I restart vim and type :map

v  ,c<Space>     <Plug>NERDCommenterToggle
n  ,c<Space>     <Plug>NERDCommenterToggle
v  ,cc           <Plug>NERDCommenterComment
n  ,cc           <Plug>NERDCommenterComment

But still, ,c<space> just behaves like I'm hitting c<space>. What's going on and how do I fix this?

Edit: tested this in VIM as well with the same behavior.

like image 569
Eric Hu Avatar asked Nov 18 '11 20:11

Eric Hu


4 Answers

Define mapleader and maplocalleader keys before any of the plugins are loaded.

Right on top of your .vimrc!

like image 145
sjas Avatar answered Nov 20 '22 01:11

sjas


The mappings seem funny, I'd expect

v  <Leader>c<Space>     <Plug>NERDCommenterToggle
n  <Leader>c<Space>     <Plug>NERDCommenterToggle
v  <Leader>cc           <Plug>NERDCommenterComment
n  <Leader>cc           <Plug>NERDCommenterComment

for them to work. I suspect you are setting the mapleader after the plugins get loaded

like image 22
sehe Avatar answered Nov 20 '22 00:11

sehe


You may have set your timeout to zero. In that case, vim won't wait for the key after the mapleader.

:set timeout timeoutlen=0 ttimeoutlen=0
like image 13
Rose Perrone Avatar answered Nov 20 '22 01:11

Rose Perrone


This will likely not be the answer for most but may help a small few...

I am running a debian distro (PureOS in my case, though the specific flavor may not totally matter) and the default \ leader key is mapped to < out of the box.

For me, remapping the key code was the fix:

sudo setkeycodes 56 43

like image 1
Jadam Avatar answered Nov 20 '22 01:11

Jadam