Get in touch
Engineering

Protect the Pinky: An RSI-Sufferer’s Story

Remap your keyboard and retrain your muscle memory to reduce pain and get back to work.

I’ve been using a keyboard for 30 years. I’ve been using a keyboard well for 10 years. Those 20 years of keyboard misuse led to RSI, most prominently in my left arm (of the ulnar nerve variety). Through trial and error, over the last decade, I’ve had to learn that modes enable more ergonomic workflows than modifier keys.

Living with any injury is a journey. Here’s the tale of the adjustments I’ve made to my workflow to make my days typing much more comfortable.

Every Mode You Make

Every app you switch to, every text input you focus, is a mode. I define a mode as a new context where the keys on your keyboard do different things. When you launch Keynote your keyboard is optimized for creating slides. When you open Spotlight (or Alfred) your enter into a search mode for apps, files, and settings.

Vim Is About Modes

Most text editors have advanced commands that can be triggered with modifier-based hotkeys. Modifier keys on a standard US keyboard are intended to be pressed with pinky fingers. Sadly, I spent all of my pinky juice crouching in Counter-Strike in the early 00s.

I switched to Vim from Emacs a decade ago because Vim’s modes greatly helped my ulnar nerve RSI. In Vim, instead of holding a key and reaching for another, you switch modes. Want to copy a line to clipboard? Exit insert mode with escape and issue a series of modifier-less commands without your fingers leaving the home row.

A demonstration of Vim’s insert and normal modes.

Over time, I’ve grown my Vim configuration into an IDE. I’ve added complexity and modes over the years. However, I still have painful RSI flare-ups from holding modifier keys. I recently discovered one of my most common, and painful, shortcuts: Command + Tab. So I went in search of a way to replace it.

Hyper Key Infatuation

Then I found the Hyper Key: a combination of all of the modifiers on the macOS keyboard (Command, Control, Option, and Shift). It’s nearly impossible to press all of those modifiers with a single hand, so no application-specific hotkeys use it.

That means you can map Caps Lock to the Hyper Key and then, add every key on the keyboard to a global shortcut that works from the context of any application.

I grew my Hyper Key mappings over time to:

  • Switch to specific apps (fewer uses of Command + Tab, yay!)
  • Move and resize windows
  • Capture a screen or record a GIF
  • Provide a pass-through to control key bindings for Terminal

I loved the power of the Hyper Key, but it only exacerbated my RSI problem. Now I had even more reason to be holding a modifier key with my left pinky.

Alfred, Meet Hammerspoon

I am also an avid user of Alfred. I use Alfred in place of Spotlight due to its customizable nature. I use Command + Space to activate Alfred hundreds of times a day and it’s painless (for my RSI injury, thumb-based modifiers aren’t painful).

Recently, the most interesting developments in macOS automation have been driven by Hammerspoon. The abstraction is just right, a programmable Lua interface to macOS with a clean API. I had been using Hammerspoon to enable my Hyper Key addiction; then I went searching for new uses of Hammerspoon that might stem my Hyper Key addiction. I stumbled on yqrashawn’s dot files and fell in love.

A Global Mode

Having a global mode means I can use my entire keyboard for shortcuts without conflicting with any application. However, I need a hotkey to invoke the global mode. Thumb-based modifiers are best for my RSI. Realizing this new mode was going to be jarring to learn, I decided to steal my Alfred shortcut (Command + Space).

The idea is simple: when I activating Alfred, I’m invariably going to be typing at least one character and pressing return. Alfred contains every app, file, and workflow on my system. What if I prefixed my Alfred command with a Hammerspoon mode? Now I can invoke very common actions with two quick key presses, Command + Space and any key on the keyboard. The beauty is that my muscle memory from using Alfred for years is still valid. Command + Space followed by c opens Chrome, d opens Dash, and so on. No need to press Return and no need to ensure the right app is shown in Alfred’s search results.

Hammerspoon’s modes can trigger actions based on single keys or even modifier keys. I’ve started adding advanced actions to certain apps, such as 2Do, using a modifier for the activation key. Command + Space and then 2opens 2Do, but Command + Space and then shift + 2 creates a new 2Do. I’ve found these advanced binding easy to remember because they work the same for every application. They are also infrequently used, so I don’t have to worry about their impact on my RSI.

I took further inspiration from yqrashawn’s dot files and moved my window movement keys to my new Hammerspoon mode. Now I can shift windows in any direction (using Vim’s hjkl movement keys), or to any monitor, using the same entry shortcut as my application launcher. Better yet, I added the ability to stay in my Hammerspoon mode by continuing to press a modifier key (command). I can repeat window movement shortcuts to place any window with precision.

Window movement with modal hotkeys.

Goodbye Command + Tab

After a few weeks of switching apps with my new mode I stopped using Command + Tab entirely. If the app isn’t in my modal shortcuts (because I use it infrequently) then I just launch or activate it with Alfred. Not having to keep a running list of my most recently activated apps in my head, for ease of switching, is transformative. Now my apps are muscle memory in a way they never were before. Better, I can even take actions within an app as muscle memory with my advanced shortcuts. Best of all, I’ve got a nearly limitless surface area to add new commands.

Hammerspoon has stayed compatible with the latest version of macOS for years, which is more than I can say for most of the other system automation software I’ve used.

Switching between Alacritty and Dash with modal hotkeys.

Don’t Copy Me

This post doesn’t end with a nice call to action to download and set up my config. Why? Because your use cases and physical aliments are different than mine. Hammerspoon is a license for any programmer (on a Mac) to modify their system to meet their needs. It’s easy to learn and powerful. You can reference my config for inspiration but I don’t recommend copying it wholesale. Instead, read the docs and search GitHub for configs and develop your own. Do it slowly, only adding a few things at a time, and you’ll succeed at re-mapping your keys and re-training your mind with a better way to work.

Jeremy Mack is a Managing Partner and Director of Engineering at Postlight. Interested in working with Postlight Engineering? Get in touch: [email protected].

Story published on Oct 2, 2019.