If you have read my previous post regarding Vim, you will know that I promised to post about my Hyper key set up. First, I should explain briefly what I mean by a Hyper key. I have a caps lock key which I never use. Vim requires the use of the escape key to switch from insert mode to normal mode, which is a very common action when writing in Vim. Escape is all the way up there in the corner so is something of a pain to reach for constantly.
Wouldn’t it be nice if caps lock could behave as an Escape key?
This is simple to do on macOS. Simply open System Preferences and select Keyboard. In the first tab (‘Keyboard’), select ‘Modifier Keys’. You can then set caps lock to either:
- Caps Lock
- Control
- Option
- Command
- Escape
- No Action
Obviously, this will do what we want. Both escape and caps lock will behave as Escape from now on. You can even change what Control, Option, Command and Function (fn) do in this preference pane.
Better, Faster, Harder, Stronger
But imagine a world where not only can you use caps lock as Escape, but you could use it for something else in different circumstances. Can you imagine it—a key that performs multiple functions?
A key that would improve your life?
Let’s say that pressing this Hyper key (I am going to call it this from now on) will simply send Escape to your system. But what if holding it down could behave as a new modifier, to go alongside your Command, Control and Option keys. So while Command-C would copy your selection, Hyper-C would, say, open VS Code. Or you could have Hyper-Return open your terminal, wherever you were in your system. You could do anything you want.
Wouldn’t you like that?
This can be achieved thanks to Karabiner Elements. In fact Karabiner Elements can do rather a lot, but I only use it for this purpose. I will leave installation to the reader—I’m sure if you are considering something like this you are well versed in application management.
Open Karabiner Elements and go to the Complex Modifications tab. Click Add Rule and one of the options will be ‘Change caps_lock to command+control+option+shift’. Enable this option.
All we have though is a new modifier. In order to give it a dual purpose, we need to edit ~/.config/karabiner/karabiner.json. You will find a section among the json like this:
"profiles": [
{
"complex_modifications": {
...
"rules": [
{
"manipulators": [
{
"description": "Change caps_lock to command+control+option+shift.",
"from": {
"key_code": "caps_lock",
"modifiers": {
"optional": ["any"]
}
},
"to": [
{
"key_code": "left_shift",
"modifiers": [
"left_command",
"left_control",
"left_option"
]
}
],
// This must be added manually
"to_if_alone": [{"key_code": "escape"}],
"type": "basic"
}
]
}
]
},
The highlighted lines need to be added manually. Now, if pressed alone, the Hyper key will send escape, but if pressed in conjunction with another key, it will behave as though Command-Control-Option-Shift have all been held simultaneously.
Actually useful
As things stand, this new Hyper key doesn’t actually do anything. You still need to put it to use. There are many options for this—I believe BetterTouchTool and Keyboard Maestro are popluar options for this sort of thing.
Myself, I use Alfred to create workflows which I assign to keyboard shortcuts utilising the Hyper key. As a simple example, I mentioned earlier setting Hyper-Return to open a terminal; This is something I have set up. As you can see from the margin note, when Alfred sees that Command-Control-Option-Shift-Return is pressed, it simply launches iTerm. This is a simple example, but I suppose you get the idea.