Vim Tip: Remapping `jj` to Escape

Vim Tip: Remapping `jj` to Escape

Eric Van Johnson • May 13, 2017

OLD POST ALERT.
We noticed you're reading an article that is over 2 years old. Some information represented in this article might have changed.
development vim

The Escape key is probably one of the more important keys for a Vim user. Whenever in insert mode, the Escape key kicks you back to normal mode. But here's the thing, the Escape key is soooooo far away.

Alright, it's not that bad, but when you are typing away, breaking away from the home row isn't optimal. I have a small mapping in my .vimrc file where, while in insert mode if I hit jj it will take me back to normal mode

Edit your .vimrc file

vi ~/.vimrc

Add the following entry

imap jj

note: you can see I have a similar mapping for kk but I honestly rarely use it

Save it and that’s it :wq

Relaunch Vim and you should now be able to hit jj while in insert mode

Mapping JJ to Escape

One Gotcha

One thing to remember with this shortcut, if you make use of recording macros when with your Vim, the jj shortcut will not work in the recording. You have to remember to actually hit the Escape key.