For 4-5 years I've had the following in my .vimrc file:

inoremap jj <Esc>

which I understand is pretty conventional, and I've never had problems until recently.

Every so often, typically when load is higher than usual, this remapping doesn't work and I end up with something like jj;wq in my document.

What would be the best way to go about increasing the reliability of this remapping? Is this uncommon, maybe indicating a system or keyboard problem?

I'm using vim version 7.4 on Ubuntu 14.04, with this .vimrc

  • Maybe you could play with the value of the 2 options 'timeout' and 'timeoutlen'. For example, if you type :set notimeout or if you increase the value of 'timeoutlen' (let's say to 3s :set timeoutlen=3000). Does it change anything ?
    – saginaw
    Jan 25 '16 at 19:59
  • @saginaw I'll try that and see if I can reproduce the problem. Jan 25 '16 at 20:31
  • Sorry set notimeout was a complete bad idea, however slightly increasing the value of 'timeoutlen' might still be worth a try. You could also look at the options 'ttimeout' and 'ttimeoutlen' but normally those only concern key codes not mappings so they shouldn't be useful here.
    – saginaw
    Jan 25 '16 at 21:31
  • It does appear the timeoutlen has an impact, if you want to post that as the answer I'll accept it. There's also a more complicated method, that doesn't quite suit my needs but is nonetheless interesting, here: vi.stackexchange.com/questions/563/… Jan 26 '16 at 14:22
  • 1
    Indeed you're right, it was very interesting to read, however I was unable to tweak the code so that it escapes from insert mode, sorry. Apart from an :echo command, the other Ex commands I tried resulted in an error E523. If my answer does not fully solve your issue, feel free to not accept it and to update your question to get more help.
    – saginaw
    Jan 26 '16 at 15:20

The options 'timeout' and 'timeoutlen' control how Vim will treat typed characters when they are part of a mapping. By default 'timeout' is enabled and 'timeoutlen''s value is 1000 (ms).
It means that by default when you hit a character that is part of a mapping, Vim will wait 1s before deciding whether you are typing the {lhs} of your mapping or if it's just a single character.

When you hit the first j in your mapping, you could imagine that Vim has triggered a timer, and you have 1s to type the second j if you want to escape. After 1s, your first j is not considered as part of a mapping anymore, it's just a character. So in the end Vim will just insert jj.

Usually Vim receives your j almost immediately after you typed it. However, if your system is under a heavy load maybe it adds some lag between the moment where you hit j and the moment Vim receives it. When it happens it's as if you typed jj with more than one second between the 2 characters. If that's the case, then you could increase the value of the 'timeoutlen' option so that your second j has enough time to reach Vim before the timeout occurs.

For example, to increase the length of the timeout to 2s, you could add in your vimrc:
set timeoutlen=2000

For more information, see:

:help timeout
:help timeoutlen

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.