Remapping keys with Karabiner Elements and Hammerspoon #117
jannis-baum
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
whoa - this is awesome! You could make entire app-specific utilities - i’ll definitely be looking into this more later |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The DistributedNotification API introduced in kV 33 allows us to remap keys by modes with the help of Karabiner Elements and Hammerspoon.
I will use this thread to illustrate this at the example of remapping
q
in Normal mode in Safari to open a new tab.Setting up a Karabiner variable to reflect kV's mode
The first step is getting Karabiner to know whether kV is in Normal mode. This is done by listening to the
kindaVimDidEnterNormalMode
andkindaVimDidExitNormalMode
notifications with Hammerspoon and using Karabiner's CLI to set a Karabiner variable accordingly. Karabiner's CLI can be found in/Library/Application\\ Support/org.pqrs/Karabiner-Elements/bin/karabiner_cli
but may be at a different location depending on your installation. Add the following to your Hammerspoon config, e.g. in~/.hammerspoon/init.lua
:With this config loaded, Karabiner will have the variable
kVNormal
set to1
or0
depending on whether kV is in normal mode. You can observe the variable with Karabiner's EventViewer App to verify everything is working correctly.Remapping the key
With this variable working, you can use it as a condition in a complex modification in Karabiner. The easiest way to configure Karabiner is using goku, which provides more concise
.edn
syntax over Karabiner's.json
. The following snippet in your~/.config/karabiner.edn
is enough to achieve our goal of remappingq
in Normal mode in Safari to open a new tab, i.e. tocmd+t
.With this in your
karabiner.edn
, rungoku
and your remapping will be live!Note: Make sure you have a Karabiner profile named
Default
or set up a different profile name with goku.Note 2: For
command+t
to actually arrive at Safari, you need to enable Passthrough forcommand
in kV's General preferences.Beta Was this translation helpful? Give feedback.
All reactions