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