Swap Escape and Caps Lock keys

When was the last time you used the Escape key on your keyboard? For a lot of you it quite probably was a fairly long time ago.

When was the last time you used the Caps Lock key? For all of you it should have been a long time ago!

I do my programming in Vim and to switch between Insert and Visual mode I have to press the Escape key. This wasn’t so much of a problem when I didn’t do so much coding, but now it’s my full-time job I find it to be quite a pain, literally. After a full week of programming in Vim my poor little finger is hurting from extending up to the Escape key.

Today I decided to solve this problem once and for all.

I mentioned the Caps Lock key earlier on. It’s on the “Home Row” of the keyboard. This means that it’s right beside where you should position your fingers when using a keyboard. Your left hand should sit on ASDF from little finger to index finger, and your right hand should sit on JKL; from index finger to little finger. You’ll notice that (on most keyboards) there is a little notch on the F and J keys. These are there to help you find the proper hand position without having to look at the keyboard. Of course, this all assumes you’re using the QWERTY keyboard layout and not Dvorak, or something entirely different.

Proper finger position

Proper finger position

In Linux there is a utility to change various keyboard and mouse settings called xmodmap. This gives you the ability to remap keys to different functionalities.

I’ve used xmodmap  to switch my Escape key fucntionality to the Caps Lock key and vice versa. This is going to take some getting used to, but the overall benefit to my fingers should be quite significant. It’ll also have the unintended side-effect of stopping me accidentally going into cPS MODE WHEN I MISS THE ‘A’ KEY. 😉 Of course, there will be some programs where pressing escape will cause the window to close, or the action to be cancelled. I guess I’ll just have to be more careful than I was before to avoid accidentally hitting the key to the left of ‘A’.

The way I set this up was using a file called .Xmodmap in my home directory. The contents of this file are loaded by xmodmap every time you log into the computer. The file contains the following:

! Swap Caps_Lock and Escape
remove Lock = Caps_Lock
remove Control = Escape
keysym Escape = Caps_Lock
keysym Caps_Lock = Escape
add Lock = Caps_Lock
add Control = Escape

Now to get back to writing code and start saving my left little finger.

One thought on “Swap Escape and Caps Lock keys

  1. Pingback: Twitted by essteeyou

Leave a Reply

Your email address will not be published. Required fields are marked *