Quickly Exiting Insert-Mode in Vim

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.

5 thoughts on “Quickly Exiting Insert-Mode in Vim”

  1. 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 .

  2. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *