Skip to content

Instantly share code, notes, and snippets.

@justinschuldt
Last active July 18, 2023 09:59
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 justinschuldt/3ce9a22c1446d65261716851c9cd57eb to your computer and use it in GitHub Desktop.
Save justinschuldt/3ce9a22c1446d65261716851c9cd57eb to your computer and use it in GitHub Desktop.
keyboard layers for MacOS with Karabiner-Elements and GokuRakuJoudo formatting
{
:layers {
; implement caps lock mode
:caps_layer {:key :caps_lock :alone {:key :escape}}
; make tab a layer if/when it is held
:tab_layer {:key :tab :alone {:key :tab}}
:backslash_layer {:key :backslash :alone {:key :backslash}}
}
; implement vs code mode
:applications {
:code ["com.microsoft.VSCode"]
}
:main [
{:des "capslock layer"
:rules [
:caps_layer
; vim keys
; navigation
[:##h :left_arrow] ; even with f, still do left arrow
[:##k :up_arrow]
[:##j :down_arrow]
[:##l :right_arrow]
[:##3 :home]
[:##4 :end]
[:##e :page_up]
[:##r :page_down]
[:##s :return_or_enter]
[:##f :delete_or_backspace]
[:##g :escape]
[:##x :delete_forward]
[:##c :!Cc] ; copy
[:##v :!Cv] ; paste
[:##b :!Cleft_arrow] ; back
[:##n :!Cright_arrow] ; forward
[:##q :!Tc] ; control + c (terminal quit, etc)
[:##w :!Cw] ; close window/tab if the app has them (chrome, vscode)
]}
{:des "tab is a layer"
:rules [
:tab_layer
;; Window stuff, similar to i3wm key
[:##e :mission_control] ; make command + space space + space space
[:##d :!Cspacebar]
[:##x :!TCq] ; lock screen
; function keys
[:##display_brightness_decrement :f1]
[:##display_brightness_increment :f2]
[:##mission_control :f3]
[:##launchpad :f4]
[:##dashboard :f5]
; [:## :f6]
[:##rewind :f7]
[:##play_or_pause :f8]
[:##fastforward :f9]
[:##mute :f10]
[:##volume_decrement :f11]
[:##volume_increment :f12]
]}
{
:des "z is command when held"
; :rules [[:##z :!CTOleft_command nil {:alone :##z}]]
; TODO - adjust this so typing "azure" fast works
:rules [[:##z :left_command nil {:alone :##z}]]
}
{
:des "/ is command when held"
; :rules [[:##slash :!CTOleft_command nil {:alone :##slash}]]
:rules [[:##slash :left_command nil {:alone :##slash}]]
},
{
:des "backslash (\\) is layer"
:rules [
:backslash_layer
;; Window management, similar to 13wm OS+Shift commands
[:##q :!Cw] ; close tabl/window
[:##left_arrow :!TOCleft_arrow] ; previous display
[:##right_arrow :!TOCright_arrow] ; next display
[:##comma :!OCleft_arrow] ; left half of screen
[:##period :!OCright_arrow] ; right half of screen
[:##3 :!OC3] ; cycle through 1/3 width positions
[:##5 :!OC5] ; cycle through 2/3 width positions
[:##4 :!OC4] ; cycle through 1/4 width positions
[:##6 :!OC6] ; cycle through 1/6 width positions
; special characters
[:##e :open_bracket]
[:##r :close_bracket]
[:##t :!Sbackslash] ; pipe
[:##d :!Sopen_bracket] ; open curly
[:##f :!Sclose_bracket] ; close curly
;[:##g :]
[:##c :!S9] ; open paren
[:##v :!S0] ; close paren
; [:##b :]
]
}
;; {:des "these only work when you are inside vscode"
;; :rules [
;; :code
;; [:p :m] ; remap p to m INSIDE VSCODE
;; ]}
{:des "switch control and command"
:rules [
[:##left_control :left_command]
[:##left_command :left_control]
]
}
]
}
;; output below is keypress events of the function row of an M1 macbook air
;; [
;; {
;; "type": "up",
;; "name": {"consumer_key_code":"display_brightness_increment"},
;; "usagePage": "12 (0x000c)",
;; "usage": "111 (0x006f)",
;; "misc": ""
;; },
;; {
;; "type": "down",
;; "name": {"apple_vendor_keyboard_key_code":"mission_control"},
;; "usagePage": "65281 (0xff01)",
;; "usage": "16 (0x0010)",
;; "misc": ""
;; },
;; {
;; "type": "up",
;; "name": {"apple_vendor_keyboard_key_code":"mission_control"},
;; "usagePage": "65281 (0xff01)",
;; "usage": "16 (0x0010)",
;; "misc": ""
;; },
;; {
;; "type": "down",
;; "name": {"apple_vendor_keyboard_key_code":"spotlight"},
;; "usagePage": "65281 (0xff01)",
;; "usage": "1 (0x0001)",
;; "misc": ""
;; },
;; {
;; "type": "up",
;; "name": {"apple_vendor_keyboard_key_code":"spotlight"},
;; "usagePage": "65281 (0xff01)",
;; "usage": "1 (0x0001)",
;; "misc": ""
;; },
;; {
;; "type": "down",
;; "name": {"key_code":"f5"},
;; "usagePage": "7 (0x0007)",
;; "usage": "62 (0x003e)",
;; "misc": ""
;; },
;; {
;; "type": "up",
;; "name": {"key_code":"f5"},
;; "usagePage": "7 (0x0007)",
;; "usage": "62 (0x003e)",
;; "misc": ""
;; },
;; {
;; "type": "down",
;; "name": {"key_code":"f6"},
;; "usagePage": "7 (0x0007)",
;; "usage": "63 (0x003f)",
;; "misc": ""
;; },
;; {
;; "type": "up",
;; "name": {"key_code":"f6"},
;; "usagePage": "7 (0x0007)",
;; "usage": "63 (0x003f)",
;; "misc": ""
;; },
;; {
;; "type": "down",
;; "name": {"consumer_key_code":"rewind"},
;; "usagePage": "12 (0x000c)",
;; "usage": "180 (0x00b4)",
;; "misc": ""
;; },
;; {
;; "type": "up",
;; "name": {"consumer_key_code":"rewind"},
;; "usagePage": "12 (0x000c)",
;; "usage": "180 (0x00b4)",
;; "misc": ""
;; },
;; {
;; "type": "down",
;; "name": {"consumer_key_code":"play_or_pause"},
;; "usagePage": "12 (0x000c)",
;; "usage": "205 (0x00cd)",
;; "misc": ""
;; },
;; {
;; "type": "up",
;; "name": {"consumer_key_code":"play_or_pause"},
;; "usagePage": "12 (0x000c)",
;; "usage": "205 (0x00cd)",
;; "misc": ""
;; },
;; {
;; "type": "down",
;; "name": {"consumer_key_code":"fast_forward"},
;; "usagePage": "12 (0x000c)",
;; "usage": "179 (0x00b3)",
;; "misc": ""
;; },
;; {
;; "type": "up",
;; "name": {"consumer_key_code":"fast_forward"},
;; "usagePage": "12 (0x000c)",
;; "usage": "179 (0x00b3)",
;; "misc": ""
;; },
;; {
;; "type": "down",
;; "name": {"consumer_key_code":"mute"},
;; "usagePage": "12 (0x000c)",
;; "usage": "226 (0x00e2)",
;; "misc": ""
;; },
;; {
;; "type": "up",
;; "name": {"consumer_key_code":"mute"},
;; "usagePage": "12 (0x000c)",
;; "usage": "226 (0x00e2)",
;; "misc": ""
;; },
;; {
;; "type": "down",
;; "name": {"consumer_key_code":"volume_decrement"},
;; "usagePage": "12 (0x000c)",
;; "usage": "234 (0x00ea)",
;; "misc": ""
;; },
;; {
;; "type": "up",
;; "name": {"consumer_key_code":"volume_decrement"},
;; "usagePage": "12 (0x000c)",
;; "usage": "234 (0x00ea)",
;; "misc": ""
;; },
;; {
;; "type": "down",
;; "name": {"consumer_key_code":"volume_increment"},
;; "usagePage": "12 (0x000c)",
;; "usage": "233 (0x00e9)",
;; "misc": ""
;; },
;; {
;; "type": "up",
;; "name": {"consumer_key_code":"volume_increment"},
;; "usagePage": "12 (0x000c)",
;; "usage": "233 (0x00e9)",
;; "misc": ""
;; },
;; ]
{
"global" : {
"check_for_updates_on_startup" : true,
"show_in_menu_bar" : true,
"show_profile_name_in_menu_bar" : false,
"unsafe_ui" : false
},
"profiles" : [ {
"complex_modifications" : {
"parameters" : {
"basic.simultaneous_threshold_milliseconds" : 50,
"basic.to_delayed_action_delay_milliseconds" : 500,
"basic.to_if_alone_timeout_milliseconds" : 1000,
"basic.to_if_held_down_threshold_milliseconds" : 500
},
"rules" : [ {
"description" : "Auto generated layer conditions",
"manipulators" : [ {
"type" : "basic",
"to" : [ {
"set_variable" : {
"name" : "caps_layer",
"value" : 1
}
} ],
"from" : {
"key_code" : "caps_lock"
},
"to_after_key_up" : [ {
"set_variable" : {
"name" : "caps_layer",
"value" : 0
}
} ],
"to_if_alone" : [ {
"key_code" : "escape"
} ]
}, {
"type" : "basic",
"to" : [ {
"set_variable" : {
"name" : "tab_layer",
"value" : 1
}
} ],
"from" : {
"key_code" : "tab"
},
"to_after_key_up" : [ {
"set_variable" : {
"name" : "tab_layer",
"value" : 0
}
} ],
"to_if_alone" : [ {
"key_code" : "tab"
} ]
} ]
}, {
"description" : "capslock layer",
"manipulators" : [ {
"from" : {
"key_code" : "h",
"modifiers" : {
"optional" : [ "any" ]
}
},
"to" : [ {
"key_code" : "left_arrow"
} ],
"conditions" : [ {
"name" : "caps_layer",
"value" : 1,
"type" : "variable_if"
} ],
"type" : "basic"
}, {
"from" : {
"key_code" : "k",
"modifiers" : {
"optional" : [ "any" ]
}
},
"to" : [ {
"key_code" : "up_arrow"
} ],
"conditions" : [ {
"name" : "caps_layer",
"value" : 1,
"type" : "variable_if"
} ],
"type" : "basic"
}, {
"from" : {
"key_code" : "j",
"modifiers" : {
"optional" : [ "any" ]
}
},
"to" : [ {
"key_code" : "down_arrow"
} ],
"conditions" : [ {
"name" : "caps_layer",
"value" : 1,
"type" : "variable_if"
} ],
"type" : "basic"
}, {
"from" : {
"key_code" : "l",
"modifiers" : {
"optional" : [ "any" ]
}
},
"to" : [ {
"key_code" : "right_arrow"
} ],
"conditions" : [ {
"name" : "caps_layer",
"value" : 1,
"type" : "variable_if"
} ],
"type" : "basic"
}, {
"from" : {
"key_code" : "3",
"modifiers" : {
"optional" : [ "any" ]
}
},
"to" : [ {
"key_code" : "home"
} ],
"conditions" : [ {
"name" : "caps_layer",
"value" : 1,
"type" : "variable_if"
} ],
"type" : "basic"
}, {
"from" : {
"key_code" : "4",
"modifiers" : {
"optional" : [ "any" ]
}
},
"to" : [ {
"key_code" : "end"
} ],
"conditions" : [ {
"name" : "caps_layer",
"value" : 1,
"type" : "variable_if"
} ],
"type" : "basic"
}, {
"from" : {
"key_code" : "s",
"modifiers" : {
"optional" : [ "any" ]
}
},
"to" : [ {
"key_code" : "return_or_enter"
} ],
"conditions" : [ {
"name" : "caps_layer",
"value" : 1,
"type" : "variable_if"
} ],
"type" : "basic"
}, {
"from" : {
"key_code" : "f",
"modifiers" : {
"optional" : [ "any" ]
}
},
"to" : [ {
"key_code" : "delete_or_backspace"
} ],
"conditions" : [ {
"name" : "caps_layer",
"value" : 1,
"type" : "variable_if"
} ],
"type" : "basic"
}, {
"from" : {
"key_code" : "g",
"modifiers" : {
"optional" : [ "any" ]
}
},
"to" : [ {
"key_code" : "escape"
} ],
"conditions" : [ {
"name" : "caps_layer",
"value" : 1,
"type" : "variable_if"
} ],
"type" : "basic"
}, {
"from" : {
"key_code" : "x",
"modifiers" : {
"optional" : [ "any" ]
}
},
"to" : [ {
"key_code" : "delete_forward"
} ],
"conditions" : [ {
"name" : "caps_layer",
"value" : 1,
"type" : "variable_if"
} ],
"type" : "basic"
} ]
}, {
"description" : "tab+d opens mission control",
"manipulators" : [ {
"from" : {
"key_code" : "e",
"modifiers" : {
"optional" : [ "any" ]
}
},
"to" : [ {
"key_code" : "mission_control"
} ],
"conditions" : [ {
"name" : "tab_layer",
"value" : 1,
"type" : "variable_if"
} ],
"type" : "basic"
}, {
"from" : {
"key_code" : "d",
"modifiers" : {
"optional" : [ "any" ]
}
},
"to" : [ {
"key_code" : "spacebar",
"modifiers" : [ "left_command" ]
} ],
"conditions" : [ {
"name" : "tab_layer",
"value" : 1,
"type" : "variable_if"
} ],
"type" : "basic"
} ]
}, {
"description" : "z is command when held",
"manipulators" : [ {
"to_if_alone" : [ {
"key_code" : "z"
} ],
"from" : {
"key_code" : "z",
"modifiers" : {
"optional" : [ "any" ]
}
},
"to" : [ {
"key_code" : "left_command"
} ],
"type" : "basic"
} ]
}, {
"description" : "/ is command when held",
"manipulators" : [ {
"to_if_alone" : [ {
"key_code" : "slash"
} ],
"from" : {
"key_code" : "slash",
"modifiers" : {
"optional" : [ "any" ]
}
},
"to" : [ {
"key_code" : "left_command"
} ],
"type" : "basic"
} ]
}, {
"description" : "switch control and command",
"manipulators" : [ {
"from" : {
"key_code" : "left_control",
"modifiers" : {
"optional" : [ "any" ]
}
},
"to" : [ {
"key_code" : "left_command"
} ],
"type" : "basic"
}, {
"from" : {
"key_code" : "left_command",
"modifiers" : {
"optional" : [ "any" ]
}
},
"to" : [ {
"key_code" : "left_control"
} ],
"type" : "basic"
} ]
} ]
},
"devices" : [ {
"disable_built_in_keyboard_if_exists" : false,
"fn_function_keys" : [ ],
"identifiers" : {
"is_keyboard" : true,
"is_pointing_device" : false,
"product_id" : 641,
"vendor_id" : 1452
},
"ignore" : false,
"manipulate_caps_lock_led" : true,
"simple_modifications" : [ ],
"treat_as_built_in_keyboard" : false
}, {
"disable_built_in_keyboard_if_exists" : false,
"fn_function_keys" : [ ],
"identifiers" : {
"is_keyboard" : false,
"is_pointing_device" : true,
"product_id" : 641,
"vendor_id" : 1452
},
"ignore" : true,
"manipulate_caps_lock_led" : false,
"simple_modifications" : [ ],
"treat_as_built_in_keyboard" : false
} ],
"fn_function_keys" : [ {
"from" : {
"key_code" : "f1"
},
"to" : [ {
"consumer_key_code" : "display_brightness_decrement"
} ]
}, {
"from" : {
"key_code" : "f2"
},
"to" : [ {
"consumer_key_code" : "display_brightness_increment"
} ]
}, {
"from" : {
"key_code" : "f3"
},
"to" : [ {
"apple_vendor_keyboard_key_code" : "mission_control"
} ]
}, {
"from" : {
"key_code" : "f4"
},
"to" : [ {
"apple_vendor_keyboard_key_code" : "spotlight"
} ]
}, {
"from" : {
"key_code" : "f5"
},
"to" : [ {
"key_code" : "f5"
} ]
}, {
"from" : {
"key_code" : "f6"
},
"to" : [ {
"key_code" : "f6"
} ]
}, {
"from" : {
"key_code" : "f7"
},
"to" : [ {
"consumer_key_code" : "rewind"
} ]
}, {
"from" : {
"key_code" : "f8"
},
"to" : [ {
"consumer_key_code" : "play_or_pause"
} ]
}, {
"from" : {
"key_code" : "f9"
},
"to" : [ {
"consumer_key_code" : "fast_forward"
} ]
}, {
"from" : {
"key_code" : "f10"
},
"to" : [ {
"consumer_key_code" : "mute"
} ]
}, {
"from" : {
"key_code" : "f11"
},
"to" : [ {
"consumer_key_code" : "volume_decrement"
} ]
}, {
"from" : {
"key_code" : "f12"
},
"to" : [ {
"consumer_key_code" : "volume_increment"
} ]
} ],
"name" : "Default",
"parameters" : {
"delay_milliseconds_before_open_device" : 1000
},
"selected" : true,
"simple_modifications" : [ ],
"virtual_hid_keyboard" : {
"country_code" : 0,
"indicate_sticky_modifier_keys_state" : true,
"mouse_key_xy_scale" : 100
}
} ]
}

vim keyboard layers for MacOS with Karabiner-Elements and GokuRakuJoudo formatting

install

setup files

cd ~/.config
touch karabiner/karabiner.json
touch karabiner.edn

add keymappings to ~/.config/karabiner.edn

{
    :layers {
        ; implement caps lock mode
        :caps_layer {:key :caps_lock :alone {:key :escape}}

        ; make tab a layer if/when it is held
        :tab_layer {:key :tab :alone {:key :tab}}
    }
        ; implement vs code mode
        :applications {
            :code ["com.microsoft.VSCode"]
        }    
     :main [
    {:des "capslock layer"
    :rules [
        :caps_layer
            ; vim keys
            ; navigation
            [:##h :left_arrow] ; even with f, still do left arrow
            [:##k :up_arrow]
            [:##j :down_arrow]
            [:##l :right_arrow]
            [:##3 :home]
            [:##4 :end]

            [:##s :return_or_enter]
            [:##f :delete_or_backspace]
            [:##g :escape]
            [:##x :delete_forward]
            ]}
    {:des "tab+d opens mission control"
    :rules [
        :tab_layer
            [:##e :mission_control]  ; make command + space  space + space  space 
            [:##d :!Cspacebar]
        ]}
    {
        :des "z is command when held"
        ; :rules [[:##z :!CTOleft_command nil {:alone :##z}]]
        :rules [[:##z :left_command nil {:alone :##z}]]
    }
    {
        :des "/ is command when held"
        ; :rules [[:##slash :!CTOleft_command nil {:alone :##slash}]]
        :rules [[:##slash :left_command nil {:alone :##slash}]]
    }
    ;; {:des "these only work when you are inside vscode"
    ;; :rules [ 
    ;;     :code
    ;;         [:p :m] ; remap p to m INSIDE VSCODE 
    ;; ]}
    {:des "switch control and command"
        :rules [
            [:##left_control :left_command]
            [:##left_command :left_control]
        ]
    }
     ]
}

run Goku to apply keymaps

goku

which will read ~/.config/karabiner.edn and output ~/.config/karabiner/karabiner.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment