Re-Map Caps Lock key to Esc in OS XI'm writing a book through O'Reilly called “Distributed Systems with Node.js” that should be published in December 2020. Click here to get more information or to sign up for an announcement.
If you are a VIM user, you probably find yourself stretching your poor little pinkey to the upper-left corner of your keyboard all of the time. How annoying! You probably also find yourself never hitting the Caps Lock key, which is totally useless since one can hold the shift key for the same effect, and annoying as heck because it is right on the home row!
Luckily, there is help. Download the PC Keyboard Hack application, and install it. This is a pretty cool app that lets us change what signals the OS interprets from key presses. It adds an entry to your System Preferences for configuring it.
To get the Caps Lock sending the escape code, you'll want to set it to 53:
Now that that is done, pressing Caps Lock will now send the escape code. Go ahead, try it out! You'll notice that the light on the key no longer toggles either.
But, we can do a little better. If you were to tap each key on your keyboard very quickly, you would notice that each of them sends their code. Even pressing the normal escape key really quickly still sends the escape code. However, if you quickly tap the caps lock key, you'll notice that it doesn't send the escape code, you actually need to hold it down maybe 100ms for the keypress to be acknowledged.
To fix this, go back to System Preferences, and go to Keyboard, then click the Modifier Keys button. On the dialog that pops up, change the Caps Lock key to perform No Action and press OK. After doing this, your Caps Lock key will be as quick as the rest of them.