Mac – How to map CAPS LOCK key in Vim

macvim

This question has already been asked here. The accepted answer says it is not possible. Other answers provide a way to do it on linux but I have not check if it worked. I am most interested in knowing if there is a way to do it for mac (although you can post answers for linux as well).

I am only reposting this question here because the other question on SOF is more than five years old. Ideally, I would like to remap to <ESC> key to CAPS LOCK.

Best Answer

If you are using the X11 environment, you may achieve what you want with the following commands:

xmodmap -e 'clear lock'

which means: from now on, Caps_Lock key isn't anymore a keyboard modifier and fall back to a normal key

xmodmap -e 'keysym Caps_Lock = Escape'

which means: get the keycode of Caps_Lock and from now on assign it the keysym of Escape.

Note: this receipe works on any Unix.