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 & visual mode
inoremap kj <esc>
vnoremap 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
" exiting 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.)
You can shorten this delay by setting a shorter timeout to timeoutlen
. For example, to have a timeout of 500ms add the following to your vimrc:
set timeoutlen=500
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:
- I tend to hit esc a lot when I'm not in insert mode just to "be sure" and
jj
would drop me 2 lines.
jk
is a no-op (down, up) but kj
is more natural for my hands.
- 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!