A while ago I wrote about my discovery of using the leader key in vim (you can read that here). Now, after using it for a while I would like to revisit it and share my experiences and what I have learned.

First of all, do not use the spacebar for your leader key, and second of all beware your timeouts.

Vim on timeout

After a while of using a custom leader key I started noticing that vim would lag for approximately a second every now and then. At first I thought it was the plugins I had installed that were causing vim to render slowly, but after removing them the problem persisted. Then I thought it was my fancy text highlighting using the cursorline settings, but after removing that too I still had the same problem. The only thing left in my vimrc were the leader key remaps.

As it turns out, vim automatically has a timeout setting that can get quite annoying when your leader key is <Space>. Essentially, vim will wait until it is sure that it has or has not recieved a mapping before typing anything to screen. This meant that everytime I hit <Space> vim would wait for up to one second before being sure that I did not type a custom leader mapping.

‘You should try it yourself and not just take my word for it’

So when I checked the vim help system I found the following two options regarding timeout:

  1. timeout
  2. ttimeout

timeout is the default behaviour of vim and it waits for an entire mapping whereas ttimeout will timeout on key codes.

This means that I wanted timeout off and ttimeout on so that my vim would continue to add keys until it matches a mapping for the leader key. You should try it yourself and not just take my word for it. Run the following commands in vim to test them out:

:set noto and :set to

:set nottimeout and :set ttimeout

Try different combinations of timeout and ttimeout to see what best suits your editing style.

Change of leadership

However, I found that using comma (’,’) instead of <Space> was a much better leader key and is not too awkward to use. The nice thing about this is that you only have to change you leader key and all your mappings will still work.