Jonathan's Blog

Hotkey Modes Should Be More Common

In my hotkey daemon skhd, I switched some of my keyboard shortcuts to shortcut modes. It reminded me how great shortcut modes are. It’s strange to me that they aren’t used more often. Outside of a few power user developer tools like Vim or Emacs, I’m not sure I’ve ever seen keyboard shortcut modes used.

Think of modes is like a tree. From the initial starting state you have several branches that you could take. Those are your initial group keyboard shortcuts. Once you hit one of those initial keyboard shortcuts, you’ve gone down one branch in the tree. Off of that branch are several more actions you can take. To give an example, say I hit alt + cmd + f to go into the branch for focusing an app. Then inside that branch I have a bunch of options for letters I could hit to focus different apps. The important part is that none of the shortcuts in the branch off the main state for focusing an app are available in the main state, and vice versa.

There are two benefits to grouping keyboard shortcuts into modes. First, it cuts down on the number of initial branch shortcuts. When most apps define keyboard shortcuts, they don’t use the tree structure of modes, but a completely flat structure. In a flat structure, any keyboard shortcut can be accessed at any time from the main state. The problem you immediately run into is that there are a lot of different actions it would be convenient to have bound to a hotkey.

A great example of this problem is my Neovim config. Currently in my config I have over 60 keymaps defined. Nearly all are defined in Normal Mode. Even though we’re already in a mode where we don’t have to set aside any keys for inputting text, if every one of those 60+ actions had it’s own special keyboard shortcut in a flat structure, I would quickly run out of keyboard combos. Adding just a bit of depth massively expands the possibilities combinations, so you’re far less likely to run into awkward collisions where it would make sense for several actions to have the same keyboard shortcut.

The second major benefit of modes is that they make shortcuts more intuitive. My skhd and Neovim configs are again a great example of this. Instead of remembering increasingly arcane and long combinations to trigger activating different common apps, you just need to remember the one common shortcut that activates the mode and the letter for the app. All of the shortcut collisions where the keyboard shortcut that makes the most intuitive sense for an action also makes sense for other unrelated actions mean that it’s difficult to keep a simple rule for what keyboard shortcut is assigned to an action. One of my favorite rules is the shortcut should be the letter of the verb or object of the action, so “i” for “information” and “b” for “browser”. But without modes how do you remember if shift + option + cmd + t is for your terminal, todos, or text editor?

A perfect example of where a flat structure gets confusing I ran into recently is the keyboard shortcuts for the Firefox developer tools. On my Mac, here are the shortcuts.

Action Shortcut
Toggle DevTools Option+Cmd+I
Toggle Browser Toolbox Option+Shift+Cmd+I
Toggle Browser Console Shift+Cmd+J
Toggle Responsive Design Mode Option+Cmd+M
Toggle Inspector Option+Cmd+L
Toggle Web Console Option+Cmd+K
Toggle JavaScript Debugger Option+Cmd+Z
Toggle Network Monitor Option+Cmd+E
Toggle Style Editor Shift+f7
Toggle Performance Shift+f5
Toggle Storage Shift+f9
Toggle DOM Option+Cmd+W
Toggle Accessibility Shift+f12

In what world do these make sense? How does the action “Toggle DevTools” have anything to do with “Option+Cmd+I”? The worst offenders by far though are the shortcuts for the Inspector, Console, Debugger, Network Monitor, Style Editor, Performance, Storage, DOM, and Accessibility. Not only do their keyboard shortcuts have almost no relation to the action, they can’t even keep the same scheme. In the UI, all of these actions are tabs in the same window. Intuitively it feels like they should have similar keyboard shortcuts, right? But no! To keep you on your toes Inspector to Network Monitor follow the pattern Option+Cmd+{letter}–again we’re setting aside the fact that {letter} has no relation to the action–but then just to keep you on your feet it switches up part way through and we instead start using Shift+{function key} style shortcuts now. None of this makes sense. It’s the equivalent of putting the create, edit, and delete buttons for the same UI object on different pages. It just doesn’t make sense.

Keyboard shortcut design is nearly as important as UI design and it’s even more important that shortcut design be as intuitive since the user doesn’t have visual hints. One of the best ways to solve this mess is modes.


Changes