Skip to content

Instantly share code, notes, and snippets.

@franklindyer
Created January 1, 2024 22:27
Show Gist options
  • Save franklindyer/1cdcacd4bee30e417f2d6ef8d3f409ff to your computer and use it in GitHub Desktop.
Save franklindyer/1cdcacd4bee30e417f2d6ef8d3f409ff to your computer and use it in GitHub Desktop.
Karabiner complex rule for balanced delimiter mapping
// Karabiner complex ruleset for convenient balanced delimiter mapping (macOS).
// To install, follow these steps:
// 1. Install Karabiner and give it permission to capture from your keyboard in System Preferences.
// 2. Go to "complex modifications" and click on "add your own rule".
// 3. Paste the below JSON configuration into the text box that opens, and click "save".
// Here are all of the mappings that it defines:
// - Map Ctrl+9 to (), placing cursor between parens
// - Map Ctrl+[ to [], placing cursor between brackets
// - Map Ctrl+] to {}, placing cursor between parens
// - Map Ctrl+4 to $$, placing cursor between dollar signs (for LaTeX)
// - Map Ctrl+, to <>, placing cursor between brackets
{
"description": "Ruleset for convenient balanced delimiters",
"manipulators": [
// Map Ctrl+9 to (), placing cursor between parens
{
"from": {
"key_code": "9",
"modifiers": {
"mandatory": [
"left_control"
],
"optional": [
"any"
]
}
},
"to": [
{
"key_code": "9",
"modifiers": [
"left_shift"
]
},
{
"key_code": "0",
"modifiers": [
"left_shift"
]
},
{
"key_code": "left_arrow"
}
],
"type": "basic"
},
// Map Ctrl+[ to [], placing cursor between brackets
{
"from": {
"key_code": "open_bracket",
"modifiers": {
"mandatory": [
"left_control"
],
"optional": [
"any"
]
}
},
"to": [
{
"key_code": "open_bracket"
},
{
"key_code": "close_bracket"
},
{
"key_code": "left_arrow"
}
],
"type": "basic"
},
// Map Ctrl+] to {}, placing cursor between parens
{
"from": {
"key_code": "close_bracket",
"modifiers": {
"mandatory": [
"left_control"
],
"optional": [
"any"
]
}
},
"to": [
{
"key_code": "open_bracket",
"modifiers": [
"left_shift"
]
},
{
"key_code": "close_bracket",
"modifiers": [
"left_shift"
]
},
{
"key_code": "left_arrow"
}
],
"type": "basic"
},
// Map Ctrl+4 to $$, placing cursor between dollar signs (for LaTeX)
{
"from": {
"key_code": "4",
"modifiers": {
"mandatory": [
"left_control"
],
"optional": [
"any"
]
}
},
"to": [
{
"key_code": "4",
"modifiers": [
"left_shift"
]
},
{
"key_code": "4",
"modifiers": [
"left_shift"
]
},
{
"key_code": "left_arrow"
}
],
"type": "basic"
},
// Map Ctrl+, to <>, placing cursor between brackets
{
"from": {
"key_code": "comma",
"modifiers": {
"mandatory": [
"left_control"
],
"optional": [
"any"
]
}
},
"to": [
{
"key_code": "comma",
"modifiers": [
"left_shift"
]
},
{
"key_code": "period",
"modifiers": [
"left_shift"
]
},
{
"key_code": "left_arrow"
}
],
"type": "basic"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment