Skip to content

Instantly share code, notes, and snippets.

@henrebotha
Last active November 9, 2024 02:22
Show Gist options
  • Save henrebotha/666bb23d5259e6c298145cb006b02202 to your computer and use it in GitHub Desktop.
Save henrebotha/666bb23d5259e6c298145cb006b02202 to your computer and use it in GitHub Desktop.
Karabiner Elements: Caps Lock + I/J/K/L to Arrow Keys (a la Pok3r)

Instructions

  1. Install Karabiner Elements
  2. Open your karabiner.json file (it will be in ~/.config/karabiner/karabiner.json).
  3. Find complex_modifications. It will have a key rules that takes a list ("rules": [...]).
  4. Inside the square brackets, paste this:
{
    "description": "Change Caps Lock + I/J/K/L to Arrow Keys",
    "manipulators": [
        {
            "from": {
                "key_code": "caps_lock"
            },
            "to": [
                {
                    "set_variable": {
                        "name": "caps_arrows_mode",
                        "value": 1
                    }
                }
            ],
            "to_after_key_up": [
                {
                    "set_variable": {
                        "name": "caps_arrows_mode",
                        "value": 0
                    }
                }
            ],
            "to_if_alone": [
                {
                    "key_code": "caps_lock"
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "name": "caps_arrows_mode",
                    "type": "variable_if",
                    "value": 1
                }
            ],
            "from": {
                "key_code": "j",
                "modifiers": {
                    "optional": [
                        "any"
                    ]
                }
            },
            "to": [
                {
                    "key_code": "left_arrow"
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "name": "caps_arrows_mode",
                    "type": "variable_if",
                    "value": 1
                }
            ],
            "from": {
                "key_code": "k",
                "modifiers": {
                    "optional": [
                        "any"
                    ]
                }
            },
            "to": [
                {
                    "key_code": "down_arrow"
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "name": "caps_arrows_mode",
                    "type": "variable_if",
                    "value": 1
                }
            ],
            "from": {
                "key_code": "i",
                "modifiers": {
                    "optional": [
                        "any"
                    ]
                }
            },
            "to": [
                {
                    "key_code": "up_arrow"
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "name": "caps_arrows_mode",
                    "type": "variable_if",
                    "value": 1
                }
            ],
            "from": {
                "key_code": "l",
                "modifiers": {
                    "optional": [
                        "any"
                    ]
                }
            },
            "to": [
                {
                    "key_code": "right_arrow"
                }
            ],
            "type": "basic"
        }
    ]
}
@kyleqihua
Copy link

since my caps lock has been used for vim. i now use the left option key. here is the code for anyone's need.

{
    "description": "Change Option + H/J/K/L to Arrow Keys",
    "manipulators": [
        {
            "from": { "key_code": "left_option" },
            "to": [
                {
                    "set_variable": {
                        "name": "option_arrows_mode",
                        "value": 1
                    }
                }
            ],
            "to_after_key_up": [
                {
                    "set_variable": {
                        "name": "option_arrows_mode",
                        "value": 0
                    }
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "name": "option_arrows_mode",
                    "type": "variable_if",
                    "value": 1
                }
            ],
            "from": {
                "key_code": "h",
                "modifiers": { "optional": ["any"] }
            },
            "to": [{ "key_code": "left_arrow" }],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "name": "option_arrows_mode",
                    "type": "variable_if",
                    "value": 1
                }
            ],
            "from": {
                "key_code": "j",
                "modifiers": { "optional": ["any"] }
            },
            "to": [{ "key_code": "down_arrow" }],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "name": "option_arrows_mode",
                    "type": "variable_if",
                    "value": 1
                }
            ],
            "from": {
                "key_code": "k",
                "modifiers": { "optional": ["any"] }
            },
            "to": [{ "key_code": "up_arrow" }],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "name": "option_arrows_mode",
                    "type": "variable_if",
                    "value": 1
                }
            ],
            "from": {
                "key_code": "l",
                "modifiers": { "optional": ["any"] }
            },
            "to": [{ "key_code": "right_arrow" }],
            "type": "basic"
        }
    ]
}

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