Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Surround with backticks in Sublime Text 3
// 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 }
]
},
]
@automaticgiant

This comment has been minimized.

Copy link

automaticgiant commented Oct 3, 2015

still needs support for multiple selections. other than that, fantastic!

@sagold

This comment has been minimized.

Copy link

sagold commented Jan 14, 2017

Thanks. Worked for me for other shortkeys than ` (backtick), since the initial backtick key is waiting for another character, i.e. e to print è

@marcusbesjes

This comment has been minimized.

Copy link

marcusbesjes commented Apr 21, 2017

nice works great here!

@njohnson7

This comment has been minimized.

Copy link

njohnson7 commented Jun 24, 2017

Thanks, that's really convenient!

@joelmellon

This comment has been minimized.

Copy link

joelmellon commented Dec 12, 2017

@andrewrech

This comment has been minimized.

Copy link

andrewrech commented Dec 19, 2017

This is wonderful, thank you

@YannDubs

This comment has been minimized.

Copy link

YannDubs commented Feb 3, 2018

@sagold If you have the backticks issue because of an international keyboard you can do this (on mac) : https://www.foobarflies.io/backticks-on-the-mac-keyboard/

@VinceSJ

This comment has been minimized.

Copy link

VinceSJ commented Feb 13, 2018

Thanks! Working great here for multi-selection and multi-cursor.

@coderCK2

This comment has been minimized.

Copy link

coderCK2 commented Jan 3, 2019

Thank you - working for multi-selection and multi-cursor for me as well!

@dakuzen

This comment has been minimized.

Copy link

dakuzen commented Aug 14, 2019

Thanks for sharing this!

@molleweide

This comment has been minimized.

Copy link

molleweide commented Sep 28, 2019

works!!!! Thx!!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.