pqrs-org / Karabiner-Elements

Karabiner-Elements is a powerful utility for keyboard customization on macOS Sierra (10.12) or later.
https://pqrs.org/osx/karabiner/
The Unlicense
18.24k stars 829 forks source link

emulating vim digraphs everywhere #2720

Open alecjacobson opened 3 years ago

alecjacobson commented 3 years ago

I'm new to Karabiner-Elements. Looks super powerful!

My goal is to enable vim digraphs everywhere. These take the form of multiple (sequently, not simultaneous keystrokes). For example,

CTRL+K then f then * produces φ

There are a bunch of very useful two-character combos for very common unicode symbols (especially mathematical symbols). I've already memorized most of the ones I need on a daily basis and would like to be able type them anywhere.

Is it possible to use use Karabiner-Elements to set up a systemwide digraphs? I looked at "Complex Modifications" but I'm not sure how to insert these kind of rules. Since there are many digraphs. I'd like to be able to add them systematically (perhaps through some .json file?). Any help is appreciated

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

eugenesvk commented 1 year ago

The following Goku script does what you want (create a new goku profile in Karabiner, read the link on how to install goku and add the script below to your goku profile, then you can either edit the resulting .json to add more digraphs or better learn a bit of Goku since it's a much more convenient syntax)

(or you could use another cool keyboard app Ukelele and create these kind of chords there, that would then also show in Keyboard Viewer)

; goku tips
  ; C T O S → left_command  left_control  left_option left_shift
  ; Q W E R → right_command right_control right_option right_shift
  ; !!      → hyper (left_command + left_control + left_option + left_shift)
  ; #optional ##optional any !mandatory

{:profiles {:goku {:default true }}

:templates {
  :say "osascript -e 'display notification \"%s\"'"
  :sym "osascript -e 'set temp to the clipboard \n set the clipboard to \"%s\" \n tell application \"System Events\" \n   keystroke \"v\" using command down \n   delay 0.1 \n end tell \n set the clipboard to temp'" ; preserves clipboard
  :symsay "osascript -e 'set temp to the clipboard \n set the clipboard to \"%s\" \n tell application \"System Events\" \n   keystroke \"v\" using command down \n   delay 0.1 \n end tell \n set the clipboard to temp' && osascript -e 'display notification \"%s\"'"
  }

;
:main [
{:des "[—————[🗍] Mod-Tap Layers—————]" :rules [[:f20 :f20]]}
 ; To allow a new layer cross with an old one, you must add :!new_name to all other mod-tap layers' conditions
{:des "  [🗍K] LCmd+K⃣ to toggle ModK: ⌘K⃣+ ⃣ ⟶ ±🗍K" :rules [
  [:!Ck [{:set["🗍K" 1]} [:say "+🗍K"]] [:!🗍K]] ;🗍K toggle on
  [:!Ck [{:set["🗍K" 0]} [:say "−🗍K"]] [ :🗍K]] ;🗍K toggle off
  ; Ia Add delayed action (https://karabiner-elements.pqrs.org/docs/json/complex-modifications-manipulator-definition/to-delayed-action/) to disable the mode after some time if needed
  ]}

{:des "  [🗍K] holdK⃣+F⃣ to 🗍F: 🗍K+K⃣  ⟶ 🗍F" :rules [ :🗍K
  [:f [{:set["🗍F"  1] :repeat false} {:set["🗍K"  0] :repeat false} [:say "+🗍F"]] [:!🗍F]] ; 🗍F 🗍ModF in ModK
    ; [:!🗍F] exclude self mode to allow binding to self in subsequent layers
    ; reset 🗍K just in case
    ; Ib OR bind other non-digraph keys to just reset 🗍K (but then typos would break the mode)
  ]}
{:des "  [🗍UI] ⇧8⃣ ⟶ φ" :rules [ :🗍F ; 🗍ModF in ModK
  ;[:!S8 [:sym "φ"] nil {:afterup  {:set["🗍F" 0]}}] ; reset 🗍ModF after one insert
  [:!S8 [:symsay "φ" "−🗍F"] nil {:afterup  {:set["🗍F" 0]}}] ; reset 🗍ModF after one insert
  ; OR to allow multiple inserts introduce another mechanism for resetting 🗍ModF (e.g. bind to ⌫)
  ]}
;

]}