This is a must-have if you're on a MacBook and use your esc key often (like VIM or Evil Emacs users do) – even more so if you remapped your caps lock key to control.
As Steve Losh points out in his Modern Space Cadet post, there are "keys you hold down to change how other keys behave, but that (usually) don’t do anything if you use them on their own" (e.g., shift), and there are "keys that you press and release but don’t want to 'repeat' as you hold them" (e.g., escape). "There are two [distinctly] different ways to use [these keys] and they’re each only useful in one of those ways. This means that we can combine them onto a single key without losing any useful functionality!"
With that in mind, we can teach the shift key to pull double duty:
- If shift is pressed and released in isolation, we can interpret it as escape
- If shift is held down and used in combination with another key, then we can let it provide the normal shift key behavior
If you've got one of those fancy Touch Bar Macs, you might find yourself longing for the good ol' days of a tactile escape key. Look no further. 😅
What's more useful than a "more useful shift key?" A more useful and more-easily reachable control key, of course. By repurposing the anachronistic caps lock key, we can skip the acrobatics needed to reach the physical control key. We can use caps lock to give us controlright on the home row.
Say goodbye to Emacs pinky. 👋
This functionality is developed and tested with the following dependencies:
- macOS Sequoia 15.2
- macOS Sierra 10.12
- Hammerspoon 1.0.0
- Hammerspoon 0.9.54
mkdir -p ~/.hammerspoon/Spoons
git clone https://github.com/monkeyjunglejuice/ShiftyEscape.spoon.git ~/.hammerspoon/Spoons/ShiftyEscape.spoon
cd ~/.hammerspoon/Spoons/ShiftyEscape.spoon
./script/setup
Optional: You're just a few seconds away from a more useful caps lock key
With one more bit of setup, you'll be able to hold caps lock for control:
Open System Preferences, navigate to Keyboard > Modifier Keys, and set the caps lock key to control. [screenshot]
All credit goes to @jasonrudolph who wrote all the code of this Hammerspoon config. I just changed the key initially used as escape from control to shift, because it's even better to reach than control mapped to caps lock on most keyboards.
Shout-out to @arbelt and @jasoncodes for the original implementation of this functionality. ⚡️🍻🌟
This code is an adaptation of their work:
- https://gist.github.com/arbelt/b91e1f38a0880afb316dd5b5732759f1
- https://github.com/jasoncodes/dotfiles/blob/ac9f3ac/hammerspoon/shift_escape.lua
Still reading? Dude, you're pretty serious about your keyboard. Lucky for you, there's more where this came from. Check out jasonrudolph/keyboard for even more fun. ⌨🤓