Why should you remap ESC key in Vim
Vim

Why should you remap ESC key in Vim

Jan 29, 2023  •  1 min read

Table of Contents

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

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

j k 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

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