Vim users remap caps to escape rnrn

Fri, Jan 15 17:02

Probably the worst nightmare of any vim user is accidentally hitting the caps key.

Caps lock is useless, for the vast majority of time, you only need to capitalize just the first letter, so pressing caps + letter + caps is too many key presses! Simply releasing the shift key is much faster and feels much better.

However most importantly, it leaves such an ergonomic key open for... escape! One of the most commonly hit keys of vim users. Such an important key is so far from the home row, almost acting counterproductive to the speed boost vim gives you.

How to remap (Linux)


On linux, if you happen to use X (which is most people), you can get away with using setxkbmap, simply include the following in your .xinitrc, or some alternative auto run script: setxkbmap -option caps:escape For the most part this will work well enough. Another option would be to make a custom key map with xmodmap, if one of these has any issues give the other a try.


You can make a custom key map by running: xmodmap -pke > ~/.Xmodmap and then simply add xmodmap "$HOME/.Xmodmap" to your .xinitrc or equivalent.

As for the actual configuration, I added these lines to .Xmodmap:

remove Lock = Caps_Lock
keysym Caps_Lock = Escape
add Lock = Caps_Lock

Oh, and also, if you screw something up and want to reset your keyboard, you can use: setxkbmap -layout us or whatever your default keyboard layout was.

How to remap (Windows)

I'm not much of a windows user, but here's a nice article from the vim website. I specifically recommend using autohotkey, as it gives you much more fine control on the behavior (you can do things like make caps function as escape only when running vim).


An alternative may be actually mapping caps to control instead, arguable a much more used key than escape in vim and especially in gui programs. Instead, you can use ctrl+[ as escape instead in vim. I'm still currently using escape, but I'll probably try control sometime in the near future. Regardless, the point is, uninstall caps lock already!

Additional Reading

Here are some links you might want to check out: