Changing from insert mode to normal mode is usually quick. The other direction is more cumbersome. You either have to reach out for the escape key, or use the Ctrl-[
(which I never got used to).
After seeing a blog post suggesting to map jk
to exit insert mode, I was inspired to create my own mapping. I chose kj
because it’s faster to type, as typing inwards is faster than outwards (you can check for yourself by tapping with your fingers on your desk). To use it, add the following to your .vimrc
:
:inoremap kj <ESC>
Now, whenever you are in insert mode, quickly typing kj
will exit insert mode. It will introduce a short pause after typing k
, but this is only a visual one, so it doesn’t actually slow you down. kj
is one of the rarest bigrams in English, so you’ll almost never have to actually type it inside a text, but if you do, just wait a bit after typing k to type the j
.
After writing this post, I’ve came across a Vim Wiki page listing all kinds of ways to avoid the escape key.
I’ve recently published my vimrc, take a look it might give you ideas for other neat tricks.
I’m mapping jj, which is even faster to type 😉
See it in my vim config:
https://github.com/MeirKriheli/dotvim/blob/master/vimrc#L118
kj stops being rare when you use it in your mapping, now you have to type it as part of your vimrc, in your blog, perhaps in help files, that’s a funny paradox…
key-combination to get out of insert mode is better starting with a key that you can’t just type as text, like .
Yoram, there’s a short timeout after the first key if not followed by the 2nd in the mapping.
In my case, if I actually need to type jj, I type the first j, wait for a fraction of a second and then 2nd. You’re left in INSERT mode and both j’s are inserted.
I’m mapping jw and jw, which is fast to type and is very uncommon in any language.
Oops – Actually mapping jw and wj so that sequence does not matter.