How to disable the leader key in vim insert mode


I mapped the leader key in vim to <Space> and I set timeoutlen to 250 to have time to use shortcuts with the leader key.

But, this is annoying in insert mode, because when I hit space, there is a small delay before the space is added (even though I did not set a binding using the leader key in insert mode) and I sometimes use a shortcut without meaning to.

Is there a way to disable the leader key in insert mode?

Thanks for your help.

Best Answer

The leader key is not special at all: if you don't use it in any mapping it works exactly like any other key.

Think of <leader> as some kind of constant that is automatically expanded to its current value when it is used. When Vim sources your vimrc and sees something like:

nnoremap <leader>b :ls<CR>:b

it will use the current value of mapleader and actually do:

nnoremap <Space>b :ls<CR>:b

What causes the delay you are observing is the fact that <Space> is used (via the <leader> mechanism in your case) at the beginning of an insert mode mapping: Vim is simply waiting a bit to see if you actually want to insert a <Space> or trigger one of the registered insert mode mappings starting with <Space>.

To see what insert mode mappings use your <leader> and where they come from, do:

:verbose imap <leader>

If the culprit is defined by a plugin, search its documentation for a way to unmap it.