How to Use CapsLock Instead of Escape in Vim

keyboard shortcutsvim

I would like to map my CapsLock to Escape. How do I represent CapsLock in .vimrc?

I know to map space to a command I would do something like this:

:map <space> viw

How would I map CapsLock to Escape without doing a registry hack – I'm looking for a Vim command?

If that is not possible without a hack or additional software I would like to assign the shortcut jj to ESC in .vimrc . I'm currently doing this:

inoremap jj <esc>

However if I'm in visual mode this does not work. How could I make jj emulate the escape key?

Best Answer

I don't think you can map CapsLock from within Vim. You remap it within X using setxkbmap:

setxkbmap -option caps:swapescape

For remapping in the console, if your distro uses systemd, you can use a custom keyboard layout in /etc/vconsole.conf as described on the Arch Wiki, and for other init systems see this U&L answer.

Related Question