With X (Linux), as @Dan Andreatta mentioned, use xmodmap
to alter the key mapping, e.g.
xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape'
Will map Esc to the CapsLock key.
You could also set this in stone by adding it into an X initialization file, such as .xinitrc
— which is run when using startx
—:
clear lock
keycode 0x42 = Escape
Typically, this is put inside an .Xmodmap
file and then it's run inside .xinitrc
.
Vim's documentation has an entire page dedicated to this topic, and the comments section is especially helful.
xmodmap
to map Caps Lock on Linux. However, anyone trying to do this in 2016 should use thesetxkbmap
command, e.g.setxkbmap -option caps:escape
. I have a little project called Uncap at github.com/susam/uncap that documents all this and also provides an unobtrusive little tool for Windows to map Caps Lock to Escape. See the Alternatives section of the README for details about usingsetxkbmap
on Linux.CAPSLOCK
toCTRL
(when pressed with other keys) ANDESC
(when pressed alone) on Windows, there is a nice piece of SW (see my answer below).CAPSLOCK
toCTRL
ANDESC
below as well.