Category Archives: Mac

Apple MacBook and other Macintosh

Karabiner & Goku: Next step is Hyper mode (Mac)

In a earlier post, I setup Karabiner with Goku to map Cmd-Ctrl-w to a series of custom keystrokes.

Why not make this even easier?

Enter “hyper” mode, which is the idea of making ANY key on your keyboard act like the Ctrl key. Basically, this is making a regular key like the “a” key a modifier key (a key to be held-down), but a regular “a” when the key is typed normally.

Based on @nikitavoloboev’s karabiner.edn file, I started with a very small config and now slowly adding more keyboard shortcuts/macros.

Here’s a simple ~/.config/karabiner.edn that makes the ‘a’ key behave like a SHIFT key, but only for the letter ‘y’. And, if you hold-down ‘a’ and tap ‘h’, it types out “Hi”:

{
  :simlayers {
    :a-mode {:key :a}
  }
  :main [{:des "a-key (launch apps, for example)"
    :rules [:a-mode
      [:y :!Sy]
      [:h [:!Sh :i]]
    ]
  }]
}

Don’t forget, to make it active (update karabiner.json) by running Goku. Or use ‘gokuw’, which will always watch for changes to your karabiner.edn:
$ goku

This means, the “a” key, used as a modifier key, can be mapped to another 40+ other keys to do 40 more custom keystrokes.
Then the “b” key in the same way, can give you another 40 more custom keystrokes.
Then the “c” key… and so on.
Even the SPACEBAR can be turned into a modifier key!

That’s a lot of new keyboard shortcuts.

When you want to add another modifier to karabiner.edn (a new “layer”), do something like this:

{
  :simlayers {
    :a-mode {:key :a}
    :d-mode {:key :d}
  }
  :main [
    {:des "a-key (stuff for vim)"
      :rules [:a-mode
          ;; complete a ctag
          [:y [:!Tx :!Tclose_bracket]]

          ;; c-x, c-p complete prev word
          [:u [:!Tx :!Tp]]

          ;; c-x, c-l complete whole line
          [:i [:!Tx :!Tl]]
      ]
    }
    {:des "d-key (dpkg)"
      :rules [:d-mode
        [:y :!Sy]
        [:p [:d :p :k :g :spacebar :hyphen :l]]
      ]
    }
  ]
}

Refs:
https://medium.com/@nikitavoloboev/karabiner-god-mode-7407a5ddc8f6

Simplify keystrokes with Karabiner and Goku (Mac keyboard macros)

Keyboard macros using Karabiner and goku

Good for making hard key sequences like ctrl-x, ctrl-] (vim completion mode) easier.

Karabiner can control almost everything keyboard-related at a low-level.
But Karabiner “Complex modifications” / “rules” are hard to configure in json, so use goku (a DSL) to write the rules in shorthand and generate the karabiner rules.

Look at your current karabiner config. Maybe save a backup:
less ~/.config/karabiner/karabiner.json

Install goku:
brew install yqrashawn/goku/goku
brew services start goku

Create the default goku .edn file, write your rules in goku format:

vi ~/.config/karabiner.edn

File contents:

donn-mbp:~ donn$ cat ~/.config/karabiner.edn
{:main [{:des "vim completion mode"
  :rules [
    ;; c-x, c-] complete tag
    [:!QWt [:!Tx :!Tclose_bracket]]

    ;; c-x, c-p complete prev word
    [:!QWw [:!Tx :!Tp]]

    ;; c-x, c-l complete whole line
    [:!QWe [:!Tx :!Tl]]
  ]
}]}

in the above, when Cmd-Ctrl-t is pressed: The app sees Ctrl-x Ctrl-]
which is vim completion-mode (ctrl-x) to complete a ctag (ctrl-])
!QW means right-cmd and right-ctrl keys are required.

Cmd-Ctrl was chosen because it works well with my Kinesis Advantage2 keyboard

How to find more symbols for special keys like ‘close_bracket’?
Search the goku source code for: grave_accent_and_tilde
(which was used in the official goku tutorial)

Run goku to translate the rules in the .edn file to karabiner json (this will update karabiner.json):
$ goku

No need to restart Karabiner to pick-up the new rule 🙂

Now from vim insert-mode, type cmd-ctrl-w to autocomplete previous word(s), which is easier than ctrl-x, ctrl-p, at least on a Kinesis keyboard.

Goku (has a tutorial with a reference of modifiers “left ctrl” to goku character-code “T”):

https://github.com/yqrashawn/GokuRakuJoudo

Next step: For something more advanced and more powerful, see my post about Karabiner “hyper” mode