Economy of Effort

Twitter LinkedIn GitHub Mail RSS

Beyond Ctrl: Make That Caps Lock Key Useful

tl;dr: Supercharge your Caps Lock key by making it Esc when tapped, and Ctrl when held

Caps Lock. A useless key sitting in prime keyboard real estate. Many software developers and power users repurpose the key by remapping it to Control.

After all, on old UNIX terminals, that’s exactly what the key to the left of “A” was:

Replacing the Caps Lock key with Ctrl makes a lot of keyboard shortcuts more convenient. But we need not stop there. Some true Men and Women of Genius came to the realization that, since Ctrl’s behavior is based around behind held down (a modifier key) and doesn’t do anything when pressed and released, it is possible to make Caps Lock do something else when tapped instead of held. For Vim users, the obvious choice is the Esc key.

We can do this in both Mac OS X and Linux.

OS X

If you want all Ctrl keys to behave like Esc when tapped

This is the easiest way, and the option I use. (I rarely find myself hitting the normal Ctrl keys anyway.)

First, open System Preferences -> Keyboard, and click Modifier Keys button. Click the Caps Lock drop-down and set it to Control:

Now, install Karabiner (formerly known as KeyRemap4MacBook). If you are a Homebrew user, you should check out Homebrew Cask and install Karabiner with $ brew cask install karabiner

Open Karabiner. Enable the first setting from the screenshot below:

The other option I have there, “Disable Escape Key”, is something I’ve done just to get myself in the habit of using the Caps Lock key for Esc. It is not required, it is just an option if you want to help train yourself to use the new key.

If you only want the Caps Lock key to behave like Esc when tapped

To do this, we’re going to take a slightly different approach. Instead of using OS X’s native Caps Lock remapping, we need to use another app, called Seil (from the same developer as Karabiner) to remap the Esc key to F19, and then use Karabiner to map F19 to our cool Ctrl/Esc hybrid key.

Install both Karabiner and Seil. (Here again, if you use Homebrew Cask, you can do this with $ brew cask install karabiner and $ brew cask install seil)

Open Seil. First, enable the “Change Caps Lock” option, and set the keycode to 80:

Next, in Karabiner, enable the “F19 for Escape and Control” option:

Linux

To accomplish the same setup in Linux, we need to use a tool called xcape.

Build and install xcape per the instructions on the project’s Wiki page. One additional step I take after building the app is copying the xcape executable to /usr/local/bin.

If you only want the Caps Lock key to behave like Esc when tapped

Add the following lines to your ~/.profile:

~/.profile
setxkbmap -option 'caps:ctrl_modifier'
xcape -e 'Caps_Lock=Escape'

If you want all Ctrl keys to behave like Esc when tapped

Same as above, except we add more arguments to the xcape line:

~/.profile
setxkbmap -option 'caps:ctrl_modifier'
xcape -e 'Caps_Lock=Escape;Control_L=Escape;Control_R=Escape'

Note: If you use some other method of remapping the Caps Lock key to Ctrl (some desktop environments have it as an option in their Keyboard settings, much like OS X), then the Caps_Lock=Escape mapping may not do anything, and you will need to use the Control_L one.

One last little tidbit: Ubuntu 14.10 (“Utopic”) has xcape in the universe repos, at least as of the time of this writing. Hopefully it will be included in Ubuntu releases from here on out.

Now Your Caps Lock Key Rules

The most useless key on the keyboard (except maybe for Pause, when’s the last time you used that?) is now your Swiss Army knife. Vim’s keybindings will make a lot more sense now that you can use your pinky the way Bill Joy did on his old ADM3A terminal:

Comments