How to use CapsLock instead of Escape in Vim?

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.


If you want to map both Caps Lock and Escape to Escape, instead of swapping them, use

setxkbmap -option caps:escape

instead of ...:swapescape.

Use

setxkbmap -option

to clear any existing options, then the above should work.