Karabiner Elements Config File

Hammerspoon is a OS X utility that provides a highlevel of customisation to control the working environment. Using it, one canspecify configuration where events such as mouse clicks and drags, and keyboardshortcuts can be used to trigger scripts or alter the environment as oneprefers.

Config

Caps Lock

The mechanism is that Karabiner-Elements watches the parent directory /.config/karabiner by using the File System Events API. Thus, Karabiner-Elements fails detecting file updates after you change the parent directory (e.g., recreate the parent directory). Karabiner-Elements The first element (pun intended) in this setup is the configuration for Karabiner-Elements. The following code JSON should be saved in a file in /.config/karabiner/karabiner.json. In our approach we will also be using Karabiner Elements for the initial key remapping, but we will be extending this functionality using Hammerspoon. First download Karabiner Elements and Hammerspoon from their pages or by using Homebrew: brew cask install hammerspoon brew cask install karabiner-elements 1. As soon as you save the file, Elements will notice it has changed, and reload its config. You should immediately have a working Hyper key 😁 If you're not confident at your ability to hand-merge JSON like this, and don't need anything from Elements other than the basic defaults, plus Hyper, feel free to grab my config and drop it in /.config/karabiner/.

For many, the caps lock key is one of the most useless keys on modernkeyboards; rarely used, it is one of the largest buttons on a keyboard withlittle useful functionality.

Karabiner Elements For Windows

You can export and import configuration by copying karabiner.json file to another machine. Open config folder from Preferences Misc. Configuration folder will be opened by Finder. Copy the karabiner.json file. Open config folder from Preferences Misc. Replace karabiner.json with the exported file. (The configuration file will be reloaded automatically.).

On the other hand, the new Macbook Pros have eliminated the escape key, one ofthe most important keys for a vim user, replacing it withthe touch bar. While the escape “key” would still be present on the touch bar,there is something reassuring about pressing a physical escape button.

An ideal solution to this is to replace the functionality of the caps lock keywith the escape key. Rather than trying to hit the missing escape key, it ispossible to map the escape key to the caps lock key, allowing for less handmovement, as well as a experiencing the tactile feedback of an actual key,rather than the touch bar.

Mapping the caps lock key to escape is fairly easy in OS X. Under SystemPreferences, Keyboard, Modifier Keys, the option to use Escape key as theaction to perform when the caps lock key is pressed.

Hammerspoon andKarabiner-Elements take this toa whole new level however, by allowing the caps lock key to function as anescape key when pressed alone, and also acting as a “hyper” key whenpressed in conjunction with other keys. This “hyper” key opens up so many morepossibilities, for having global or application specific function keys,especially when combined with Hammerspoon.

Karabiner-Elements

The first element (pun intended) in this setup is the configuration forKarabiner-Elements. The following code JSON should be saved in a file in~/.config/karabiner/karabiner.json. This config remaps the caps lock key tosend the escape key when pressed alone, while sending the command, control andoption keys when pressed in conjunction with other keys.

Hammerspoon Configuration

Karabiner Elements Config File Extension

The following Hammerspoon configuration should be saved to ~/.hammerspoon/init.lua.

Karabiner

It defines hyper as the combination of command, control and option beingpressed at the same time, which has been remapped to the caps lock key.shyper is defined as the same combination, in addition with the shift key.

There are various utility functions defined, then the main hyper/shyper keybindings are specified.

Karabiner Elements Config FileKarabiner Elements Config File

For now, there are simple terminal, firefox and finder window launching, aswell as a quick shortcut for putting the computer’s display to sleep.

Karabiner Elements Download

Hammerspoon is not only limited to launching commands triggered by keystrokes.There is a section devoted to window layout, sending windows to various gridlocations. If you imagine a screen being split into 4 quadrants, there arevarious key bindings (in association with the caps lock/hyper remapping) tosend windows to occupy various quadrants. This allows a focused window to bequickly mapped to a region of the screen.

There is also a section devoted to using the mouse to control layout ofwindows. By grabbing the title bar of a window and dragging to either the edgeor corner of the screen, the related window will be resized and positionedappropriately.

Concluding the configuration, there are a few miscellaneous items and commentsfor future plans :)

Json

My configuration for Karabiner-Elements, Hammerspoon and other utilities can be downloaded from my github config repository.

Karabiner Elements Config Files

  • More Hammerspoon sample configurations
  • A Modern Space Cadet An excellent writeup of one user’s extensive custom configuration