Spring Loading Karabiner in the Autumn
Richard Mortier · October 30, 2017 · #tech #config #dotfiles #macosI recently took the plunge and upgraded my OS X. Not to vN of Sierra as I’d hoped, but to v0 High Sierra– the perils of waiting too long…
Unfortunately, this toasted1 my carefully curated keyboard remappings as Karabiner used a kernel extension, for which everything changed. All was not lost however, as the rewrite to support Sierra/High Sierra was well underway. Or so I thought until I realised that the configuration file had changed from XML to JSON. And so my configuration journey began. (But it all ends well, so that’s good.)
To be honest, I suspect even the Sierra upgrade would’ve done this.
Controlling the config
The first thing was to get the new configuration matters under control. I did this per the documentation, symlinking the config subdirectory from my rc-files
repo:
Internal Apple keyboard
In the interests of keeping all configuration in one place (but see below), I decided to do this via a set of complex modifications. In summary this meant:
- swap
(caps_lock)
and(control)
:
,
- swap
"
(glyphS-'
) with@
(glyphS-2
):
,
- map
(backslash)
(glyph\
) to#
, andS-\
(glyph|
) to~
:
- map
(non_us_backslash)
(glyph§
) to`
andS-(non_us_backslash)
(glyph±
) to€
, and then patch things up so that the usual window switching works (using(command)-`
):
,
- finally, map
`
to\
andS-`
to|
,
iTerm2
Unfortunately for me, iTerm2 then gets a bit confused as it wants to leave (command)
alone, only allowing mapping of (option)
to (meta)
(or, in fact, (esc+)
). In the past I swapped (left_command)
and (left_option)
to make the usual shell (bash
) CLI editing combinations (roughly, emacs
) work. That wasn’t ideal though as I then had to fix up the window cycling commands ((command)-`
and so on). Fortunately, the fix this time seems easier: just configure the two tricky mappings (involving generating a keypress modified with (option)
) to be interpreted by iTerm2 to just send the appropriate text through. Again, I did this in the UI (Preferences > Profiles > Keys) but the resulting configuration change is also straightforward:
Keyboard Map
...
0x32-0x80000
Action
12
Text
€
...
0x33-0x80000
Action
12
Text
#
...
Microsoft Digital Media keyboard
Examining the key codes using the Karabiner Event-Viewer, it seemed that the first thing to do was to swap (grave_accent_and_tilde)
(glyph `
) and (non_us_backslash)
(slightly confusingly, glyph \
on my keyboard). I started out trying to do this as a complex modification so that all the remappings were in one file, but couldn’t: I couldn’t figure out how to control the application order of mappings in that file. However, simple modifications are applied before complex modifications, and this is a simple modification as it’s a direct swap, so I just used the UI and did it there. For the sake of completeness, the resulting modification to karabiner.json
is:
The next step was to patch up the complex modifications. Once I realised that the event viewer was claiming that the key with glyph #
was emitting (backslash)
while it was, in fact, emitting (non_us_pound)
, this was fairly straightforward:
- swap
(command)
(glyphAlt
) and(option)
(glyphStart
):
,
]
},
- add coverage of
(non_us_pound)
to the rule that remaps\
to#
:
,
…and that’s it. My keyboard is, once again, my castle.