Skip to content

Instantly share code, notes, and snippets.

@gsinclair
Created January 10, 2022 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsinclair/9233f4efc089e6671a271706a2fce0d3 to your computer and use it in GitHub Desktop.
Save gsinclair/9233f4efc089e6671a271706a2fce0d3 to your computer and use it in GitHub Desktop.
A Karabiner/Goku example that among other things demonstrates swapping Win and Alt keys on an external keyboard to reflect the Mac Option-Command layout.
{
:devices {
:sculpt-keyboard [{:product_id 1957 :vendor_id 1118}]
}
:layers {:capslock-mode {:key :caps_lock :alone {:key :escape}}
; CAPSLOCK gives arrow keys with hjkl and Enter with m or Escape if tapped
}
:simlayers {
:f-mode {:key :f} ; delimeters ( ) [ ] { } < >
:d-mode {:key :d} ; arithmetic + - * / = % \[ \]
:s-mode {:key :s} ; punctuation ? ! : ; ' " ` ~
:a-mode {:key :a} ; symbols & | _ \ @ # $ ^
;
:q-mode {:key :q} ; General shortcuts (browser etc.)
:w-mode {:key :w} ; Selection left and right (letter, word, line)
:e-mode {:key :e} ; Movement left and right (letter, word, line)
:r-mode {:key :r} ; Deletion left and right (letter, word, line)
;
:g-mode {:key :g} ; Mouse scroll, desktop left-right, zoom in-out, screenshot
;
:v-mode {:key :v} ; Number pad
}
:main [
{:des "Swap Win and Alt on Sculpt keyboard"
:rules [:sculpt-keyboard
[:left_option :left_command]
[:left_command :left_option]
[:right_option :right_command]
[:application :right_option]
]
}
;;; This doesn't work because ... well, I set CAPS-LOCK = Control in the Mac
;;; keyboard settings, but Karabiner doesn't see that when processing these
;;; rules :(
;;;
;;; {:des "CTRL-[hjklm] to arrow movement and Enter, or Esc if alone"
;;; :rules [
;;; [:!Th :left_arrow]
;;; [:!Tj :down_arrow]
;;; [:!Tk :up_arrow]
;;; [:!Tl :right_arrow]
;;; [:!Tm :return_or_enter]
;;; ]
;;; }
{:des "CAPS LOCK - arrow movement [hjkl] and delete [g;] and Return [m], otherwise CTRL-*, otherwise Escape"
:rules [:capslock-mode
[:h :left_arrow]
[:##j :down_arrow]
[:##k :up_arrow]
[:##l :right_arrow]
[:n :return_or_enter]
[:m :return_or_enter]
[:!Ch :!Cleft_arrow]
[:!Cj :!Cdown_arrow]
[:!Ck :!Cup_arrow]
[:!Cl :!Cright_arrow]
[:!Oh :!Oleft_arrow]
[:!Oj :!Odown_arrow]
[:!Ok :!Oup_arrow]
[:!Ol :!Oright_arrow]
[:!Sh :!Sleft_arrow]
[:!Sj :!Sdown_arrow]
[:!Sk :!Sup_arrow]
[:!Sl :!Sright_arrow]
[:!OSh :!OSleft_arrow]
[:!OSj :!OSdown_arrow]
[:!OSk :!OSup_arrow]
[:!OSl :!OSright_arrow]
[:!CSh :!CSleft_arrow]
[:!CSj :!CSdown_arrow]
[:!CSk :!CSup_arrow]
[:!CSl :!CSright_arrow]
;; Jan 2022: I'm trying better options for these actions.
;; [:##g :delete_or_backspace]
;; [:##semicolon :delete_forward]
;; [:##w :!Odelete_or_backspace]
;; [:##m :return_or_enter]
[:##q :!Tq]
[:##w :!Tw]
[:##e :!Te]
[:##r :!Tr]
[:##t :!Tt]
[:##y :!Ty]
[:##u :!Tu]
[:##i :!Ti]
[:##o :!To]
[:##p :!Tp]
[:##a :!Ta]
[:##s :!Ts]
[:##d :!Td]
[:##f :!Tf]
[:##g :!Tg]
[:##z :!Tz]
[:##x :!Tx]
[:##c :!Tc]
[:##v :!Tv]
[:##b :!Tb]
; [:##n :!Tn] These are now Enter
; [:##m :!Tm]
[:##1 :1]
[:##2 :2]
[:##3 :3]
[:##4 :4]
[:##5 :5]
[:##6 :6]
[:##7 :7]
[:##8 :8]
[:##9 :9]
[:##0 :0]
[:##hyphen :hyphen]
[:##equal_sign :equal_sign]
[:##open_bracket :open_bracket]
[:##close_bracket :close_bracket]
[:##semicolon :semicolon]
[:##quote :quote]
[:##comma :comma]
[:##period :period]
[:##slash :slash]
]
}
{:des "f-mode for delimeters" ;; { } ( ) [ ]
:rules [:f-mode
[:##j :!S9] ; f -> j (
[:##k :!S0] ; f -> k )
[:##m :open_bracket] ; f -> m [
[:##comma :close_bracket] ; f -> , ]
[:##u :!Sopen_bracket] ; f -> u {
[:##i :!Sclose_bracket] ; f -> i }
; The next two are in for legacy reasons.
[:##l :open_bracket] ; f -> l [
[:##semicolon :close_bracket] ; f -> ; ]
]
}
{:des "d-mode for arithmetic" ;; < > # + - = * / ~
:rules [:d-mode
[:##u :!Scomma] ; d -> o <
[:##i :!Speriod] ; d -> p >
[:##o :!S3] ; d -> o #
[:##j :!Sequal_sign] ; d -> j +
[:##k :hyphen] ; d -> k -
[:##l :equal_sign] ; d -> l =
[:##m :!S8]
[:##comma :slash]
[:##period :!Sgrave_accent_and_tilde]
]
}
{:des "s-mode for punctuation" ;; ; : ! , . ? ' " `
:rules [:s-mode
[:##u :semicolon]
[:##i :!Ssemicolon]
[:##o :!S1]
[:##j :comma]
[:##k :period]
[:##l :!Sslash]
[:##m :quote]
[:##comma :!Squote]
[:##period :grave_accent_and_tilde]
]
}
{:des "a-mode for symbols"
:rules [:a-mode
[:##j :!S7] ; a -> j &
[:##k :!Sbackslash] ; a -> k |
[:##l :!Shyphen] ; a -> l _
[:##semicolon :backslash] ; a -> ; \
[:##u :!S2] ; a -> u @
[:##i :!S3] ; a -> i #
[:##o :!S4] ; a -> o $
[:##p :!S6] ; a -> p ^
]
}
{:des "r-mode for deleting characters with ui, words with jk and lines with hl"
:rules [:r-mode
[:##u :delete_or_backspace] ; r -> j Delete word backwards
[:##i :delete_forward] ; r -> j Delete word backwards
[:##j :!Odelete_or_backspace] ; r -> j Delete word backwards
[:##k :!Odelete_forward] ; r -> k Delete word forwards
[:##h :!Cdelete_or_backspace] ; r -> h Delete to beginning of line
[:##l :!Cdelete_forward] ; r -> l Delete to end of line
]
}
{:des "e-mode allows for easy back and forth one character, word or line"
:rules [:e-mode
[:##u :left_arrow] ; e -> u Left
[:##i :right_arrow] ; e -> i Right
[:##j :!Oleft_arrow] ; e -> j Opt+Left
[:##k :!Oright_arrow] ; e -> k Opt+Right
[:##h :!Cleft_arrow] ; e -> h Cmd+Left
[:##l :!Cright_arrow] ; e -> l Cmd+Right
[:n :return_or_enter] ; e -> n Enter
[:m :return_or_enter] ; e -> n Enter
]
}
{:des "w-mode = e-mode + SHIFT (i.e. selection, not just movement)"
:rules [:w-mode
[:##u :!Sleft_arrow] ; e -> u Shift+Left
[:##i :!Sright_arrow] ; e -> i Shift+Right
[:##j :!SOleft_arrow] ; e -> j Shift+Opt+Left
[:##k :!SOright_arrow] ; e -> k Shift+Opt+Right
[:##h :!SCleft_arrow] ; e -> h Shift+Cmd+Left
[:##l :!SCright_arrow] ; e -> l Shift+Cmd+Right
]
}
{:des "q-mode for general shortcuts like browser tab navigation"
:rules [:q-mode
[:##j :!CSopen_bracket] ; q -> j tab to the left: Cmd-{
[:##k :!CSclose_bracket] ; q -> k tab to the right: Cmd-}
[:##l :!TCf ] ; q -> l toggle full screen: ^⌘F
[:##u :!Cclose_bracket] ; q -> u browser back: Cmd-[
[:##i :!Cclose_bracket] ; q -> i browser forward: Cmd-]
[:##o :f2 ] ; q -> o F2 (useful in Excel)
[:##p :f4 ] ; q -> p F4 (useful in Excel)
]
}
{:des "v-mode for number pad uio jkl m,."
:rules [:v-mode
[:u :7]
[:i :8]
[:o :9]
[:j :4]
[:k :5]
[:l :6]
[:m :1]
[:comma :2]
[:period :3]
[:p :0]
[:semicolon :period]
[:slash :0]
[:y :0]
[:h :0]
[:n :0]
]
}
{:des "c-mode for slash and line type symbols"
:rules [:c-mode
]
}
{:des "g-mode for mouse scroll, desktop left-right, zoom in-out, screenshot"
:rules [:g-mode
]
}
{:des "Forward slash is an easier right-shift (if combined)"
:rules [
[:slash :left_shift nil {:alone :slash}]
]}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment