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


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?

  • 4
    Ctrl-[ is the same as 'ESC'
    – Herb
    Aug 1 '18 at 21:20
  • 1
    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 '18 at 23:31
  • 1
    Also, the capital letters aren't necessary.
    – Beam Davis
    Aug 1 '18 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 '18 at 12:48
  • 1
    While brevity is cool and everything...it's the soul of wit after all...I'm guessing you meant something else. Clarity? Verbosity? Non-brevity? ;)
    – B Layer
    Aug 28 '18 at 4:11


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 Dec 4 '18 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. Dec 4 '18 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 Dec 4 '18 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. Dec 6 '18 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) Dec 6 '18 at 7:12

If you have a non-English keyboard layout, you can turn the extra keys into your advantage!

For example, Hungarian layout has the ö (o umlaut) where 0 would be on an English keyboard. Most would never use this letter in vim.

So I just remap Esc to it everywhere without fear. But as Bruno found out, in command mode remapping to Esc alters the behaviour, so there we use the equivalent Ctrl+C:

nnoremap ö <esc>         " Remap in Normal mode
inoremap ö <esc>         " Remap in Insert and Replace mode
vnoremap ö <esc>         " Remap in Visual and Select mode
xnoremap ö <esc>         " Remap in Visual mode
snoremap ö <esc>         " Remap in Select mode
cnoremap ö <C-C>         " Remap in Command-line mode
onoremap ö <esc>         " Remap in Operator pending mode

Put the above in your ~/.vimrc.

  • 2
    They are not equivalent! Simple example: 5ii<esc> vs 5ii<c-c>
    – D. Ben Knoble
    Nov 10 '20 at 13:22

If you don't have a qwerty keyboard and you cannot press <C-[>, simply <C-C> works fine ! And for any mode ! the only sad thing is the prompt when you press <C-C> in normal mode, telling you that you should press :qa to quit vim.

  • 2
    See my comment on Neinstein’s answer. They are not equivalent, it will not work “just fine”.
    – D. Ben Knoble
    Apr 10 at 13:24
  • thanks for that, i did not know that they where not the same ! Sep 19 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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