5

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.

8

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.

  • Thanks. I found the plugin defining the mappings with the verbose command. – antoyo Jul 26 '15 at 15:18
  • 4
    Once you've found the culprits you can make a folder ~/.vim/after/plugin and put a new file in there called something like unmap.vim. In this file you can put unmap commands. One of mine are iunmap <Leader>is which is a mapping from a.vim. – Paymahn Moghadasian Feb 9 '16 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.