logo

Why should you remap ESC key in Vim

Why should you remap ESC key in Vim

By default,the ESC key is used to switch to Normal mode from Insert mode. But as you can see on a regular keyboard, the position of ESC key is far from the home row keys. To press it without lifting your entire hand, you have to extend your pinky finger. This is fine if you are doing some light typing/editing. But doing this for prolonged typing/editing sessions, this can be quite exhausting.

The solution is to remap the ESC to jk.

Command

inoremap jk <esc>

Explanation

  • inoremap : Use this mapping in Insert mode
  • jk : The keys to be pressed
  • <esc> : The keypress that will get executed

When jk is pressed immediately in Insert mode, VIM will exit Insert mode and go to Normal mode.

jk is used because very rarely you will need to type words containing the character k followed by j.

But transitioning from pressing ESC to pressing jk can be difficult as you are used to old mapping.

To break this habit, you will have to disable the ESC key.

Command

inoremap <esc> <nop>

Explanation

  • inoremap : Use this mapping in Insert mode
  • <esc> : The key that will be pressed
  • <nop> : Means no operation will be executed

Once you get used to it, you can restore the original key binding.

Built using GatsbyJs and hosted on Netlify© Copyright 2024, Gautam Naik