How to swap Caps-lock and Esc keys in Ubuntu
Here’s a productivity tip that has saved me countless work while typing. Swap your Caps-lock and Escape keys. If you’re like most people, you use Caps-lock virtually never, and Escape quite a lot. Especially if you’re a programmer who happens to use the best text editor, Vim. Read on to learn how to do this.
An easy way to do it on Ubuntu with Gnome: step one, create a .xmodmaprc file. You can run the following command to create the file and put the correct contents into it:
echo > ~/.xmodmaprc '! Swap caps lock and escape remove Lock = Caps_Lock keysym Escape = Caps_Lock keysym Caps_Lock = Escape add Lock = Caps_Lock'
Step two is to make this run every time you log in. Open up System-Preferences-Settings. Click the Add button to add a new entry to the additional startup programs list. In the “name” box, enter “xmodmap” or something else descriptive. In the Command box, enter “/usr/bin/xmodmap /home/[user]/.xmodmaprc”, where [user] is your username.
And now get used to being able to hit Escape without reaching for it. If you like this, you might also be interested in using the Dvorak keyboard — I can type on either Dvorak or QWERTY, but Dvorak has saved me from something approaching total paralysis of the hands, so it’s worth checking into also.
As your reward for reading this far,
Q: what’s the integral of 1/cabin?
A1: Natural Log Cabin
A2: Houseboat (Natural Log Cabin + C)



A better way to do this is to go into System > Preferences > Keyboard. Then go to “Layouts”, click on “Layout Options…” and expand the “CapsLock key behaviour” group. There, you’ll see “Swap ESC and CapsLock”.
But what I find really nice is to make CapsLock a Control key. Then I just type Control-[ which is also ESC.
Simon Law
22 Oct 08 at 6:35 pm
For those who come here looking for an OS X solution you might want to look at http://www.pqrs.org/tekezo/macosx/keyremap4macbook/extra.html
Arnaud
24 Oct 08 at 3:51 am
Simon, thanks for the tip. I have found that the solution Baron posted works sometimes and sometimes it doesn’t work, and I don’t know why. I didn’t know you could customize the keyboard so much in Gnome. Cool!
Thanks Baron for posting the solution, it has helped for about a year!
Nathaniel
1 Nov 08 at 11:49 pm
I’ve found that the Gnome built-in keyboard layout ability isn’t that smooth. For example if I set up Dvorak, I still have to press CTRL-D (the key labeled D) to get a CTRL-D. I can’t press CTRL-[key remapped to D]. But other things randomly seem to be remapped even with CTRL. It’s quite odd.
Xaprb
19 Jan 09 at 3:04 pm