Is it possible to remap the Esc key to another key in Vim? When I'm using Vim in a full screen VMware vSphere web client console window and I press the Esc key to exit edit mode, it also takes me out of full screen mode in the console window.

I am using the Vim that comes from the RHEL YUM repo. (RHEL 7.5; Vim 7.4).

up vote 2 down vote accepted

Usually, C-[ is also a way to get out of insert mode. Some people like to map jj in insert mode as a way to exit and return to normal mode. I personally prefer jh as my fingers 'slide' better with this and I don't strain my middle finger much.

From somewhere in my neovim settings:

inoremap jh <Esc>

This remaps jh to escape in insert mode.

Is this what you wanted?

  • 1
    Ctrl-[ is the same as 'ESC' – Herb Wolfe Aug 1 at 21:20
  • Yes, that works perfectly. Thanks! – Beam Davis Aug 1 at 22:40
  • I played around and also discovered this works: ":inoremap <F1> <Esc>". This maps the F1 key in the place of the Esc key. This can be shortened to ":ino <F1> <Esc>". – Beam Davis Aug 1 at 23:31
  • Also, the capital letters aren't necessary. – Beam Davis Aug 1 at 23:38
  • Yeah, capitals aren't necessary and 'ino' is shorter to write, but in my configs I prefer brevity over cool-shortcuts. I'm glad I helped! – Amir Eldor Aug 2 at 12:48

TL;DR

It's actually nice to remap esc to the home row. Here's how you decide what to map it to: Pick a hand and roll your 4 fingers across your desktop as fast as you can in whichever direction is fastest. Use that to choose what keys to remap.

For me it's more natural to roll from pinky to index finger. Therefore I chose to use kj. Also, I did a grep -rHin kj ~/src (recursive grep on the parent directory of all my source code) and found no matches.

" esc in insert mode
inoremap kj <esc>

" esc in command mode
cnoremap kj <C-C>
" Note: In command mode mappings to esc run the command for some odd
" historical vi compatibility reason. We use the alternate method of
" existing which is Ctrl-C

Note: If you do need to type a literal kj (or whatever your mapping is) just type them with 2 seconds in between. (You'll see the cursor hesitate to move after the 1st char. Wait for it to move before typing the 2nd.)


I have been using vim for 19 years. I was horrified when Apple updated their MacBook Pros to have a touch bar and no physical esc key. I saw a post that suggested mapping jj and jk to <Esc> and hated it. But I patiently jotted down on an index card every time it annoyed me. About 15 minutes later I reviewed my notes and came up with the TL;DR above to address the following:

  1. I tend to hit esc allot when I'm not in insert mode just to "be sure" and jj would drop me 2 lines.
  2. jk is a no-op (down, up) but kj is more natural for my hands.
  3. I also need to use esc to exit command mode without completing the command.

It's my hope that I can finally break my habit of hitting esc in other applications and closing windows when I'm several minutes into writing. I'd much rather insert stray kj characters than lose my work!

  • 1
    Note, for your cnoremap, when the esc comes from a mapping, it will execute the command, rather than aborting it. That is for compatibility reasons with vi – Christian Brabandt Dec 4 at 7:01
  • In both insert and command mode, esc still works. But, you also have this alternative home row combo that you also use. Maybe I didn't follow your point. – Bruno Bronosky Dec 4 at 7:34
  • 2
    the point is, for command mode, an escape that comes from the mapping will not abort the command, but run it. Try :ls kj – Christian Brabandt Dec 4 at 7:46
  • @ChristianBrabandt you are correct. What can be done about it? Or at least, where is this documented? I can't even come up with decent search terms to find anything about this. – Bruno Bronosky Dec 6 at 3:06
  • 1
    I don't remember whether this is being documented, I stumbled over that behaviour several years ago. Ah, it is kind of documented at :h c_Esc: In macros [...] start entered command. (Macros usually also include mappings) – Christian Brabandt Dec 6 at 7:12

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.