Vim: How to Remap Escape Key?

Buy Xah Emacs Tutorial. Master emacs benefits for life.
, , …,

How to make Caps Lock key do Escape key?

Use Operating System's keymap mechanism to make Caps Lock send Esc. (Or, if you have a special keyboard such as Logitech Gaming Keyboards or Truly Ergonomic Keyboard, use its firmware)

For Linux, see:

for Mac:

for Microsoft Windows:

You can't do this with vim init file because the Caps Lock is not seen at software applications layer.

How to make vim use some other key to do Escape?

Create a file at ~/.vimrc, and put the following

"make jj do esc"
inoremap jj <Esc>

"make esc do nothing"
inoremap <Esc> <Nop>

this will make 【jj】 do Esc, and disable the Esc key. (thanks to 00Davo〔➤ Programer Hand Health: vi Esc Key Syndrome#comment-1426377905〕)

if you have a special keyboard (such as the ergodox 〔➤ Ergonomic Keyboards〕 ) where the {↖ Home, ↘ End} keys are right under your thumbs, then you can make them do command mode and insert mode, like this:

"make home key do esc when in insertion mode"
:imap <Home> <Esc>

"make end key go to insertion mode, when in command mode"
:map <End> i

"turn on line numbering"
:set number

in vim, how to find what a key does? (in emacs its “describe-key”.)

Type :help key to show it in help.

Type :map key to show customized key in command mode . (that is, defined in init file.)

Type :imap key to show customized key in insert mode . (that is, defined in init file.)

Like it?
Buy Xah Emacs Tutorial
or share
blog comments powered by Disqus