Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cdnadmin/cc0593d2eaf63fbe40951a1e9334a595 to your computer and use it in GitHub Desktop.
Save cdnadmin/cc0593d2eaf63fbe40951a1e9334a595 to your computer and use it in GitHub Desktop.
Auto pair selected text & auto selections.
/******************************************************************************************
Taken from https://gist.github.com/beechnut/69a3ab6fd66f03e8e5ea
Thank you @beechnut & others references below!
July 26, 2018 -- run and tested in Sublime Text 3.1.1 (subl)
1. In subl, go to menu item, "Sublime Text"-->Preferences-->"Key Bindings"
2. Copy and paste below config to "Default.sublime-keymap" file & save.
3. Test it out by opening file and:
3.1 highlight a contiguous select (single and/or multi-word)
3.1.2 type back tick (`) --> should surround selection with back ticks.
3.2 highlight multiple areas via subl multi-cursor
3.2.2 type back tick (`) --> should surround all, multi-cursor selections with back ticks.
*******************************************************************************************/
// Copy the following into Preferences > Key Bindings -- User
// Thanks to:
// http://sublimetext.userecho.com/topic/86166-backtick-quoting-selected-text-does-not-work-like-single-quotes-and-double-quotes/
[
// Auto-pair backticks
{ "keys": ["`"], "command": "insert_snippet", "args": {"contents": "`$0`"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|>|$)", "match_all": true },
{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "[`a-zA-Z0-9_]$", "match_all": true },
{ "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.single", "match_all": true }
]
},
{ "keys": ["`"], "command": "insert_snippet", "args": {"contents": "`${0:$SELECTION}`"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
]
},
{ "keys": ["`"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^`", "match_all": true }
]
},
{ "keys": ["backspace"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Delete Left Right.sublime-macro"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "`$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^`", "match_all": true }
]
},
]
@cdnadmin
Copy link
Author

Referenced in short blog entry, "Sublime Text, Auto Pair Back Ticks Configuration"

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