Swap Esc and CapsLock on Ubuntu

As a Vim user with small hands, it’s very uncomfortable having to stretch the pinky finger out to reach the Esc key over and over. There must be a better way!

Some history

Vi, the old vi-sual editor predecessor of Vim, was originally created by Bill Joy in 1976, working on an ADM-3A. The machine was a dummy terminal connected over modem sending information at a meager 300 baud rate. The data rate was so slow that the screen couldn’t keep up with the characters Bill was typing. There’s an old interview in Linux Magazine from 1999 where Bill talks about those early days.

The point is, the machine’s keyboard where Vi was created looked like this:

Terminal ADM-3A keyboard

So the Esc key was in the position we currently find the Tab key, which is a very sensible choice. Now, since I actually use the Tab key a lot, I’m not going to swap it, instead I’m going to swap CapsLock and Esc. The next best thing.

Swapping the keys

Let’s do this. Open the keyboard configurations file:

sudo vim /etc/default/keyboard

And add the following line:

XKBOPTIONS="caps:swapescape"

Reboot for the changes to take effect and check if it works. It used to work on Ubuntu with Gnome, until it didn’t. For Ubuntu - I assume this also works for other distros using Gnome - run the command:

gsettings set org.gnome.desktop.input-sources xkb-options \
"['caps:swapescape']"

And that should do the trick!

To learn more about keyboard distributions check this humble guide to XKB on Linux and the Arch docs about keyboard configurations.