+14

Backtick quoting selected text does not work like single quotes and double quotes

Stuart Roebuck fa 12 anys updated by Lucas Siqueira fa 7 anys 4
Currently, if you select some text and type a quote or a double quote, ST2 will place the quote at both ends of the selected text.  This is a nice feature.

If, however, you are editing text in Markdown there is often the need to use backticks around code elements.  When you select text and type a backtick the text is completely replaced by a single backtick.  It would be nice if ST2 could place a backtick at each end of the selection.

The same thing happens when editing SQL, after selecting and table name you may want to surround it with backticks.

+12

Although I think this should bin the defaults, you can enable this yourself. Search for the "Auto-pair single quotes" block when editing the default key bindings block. Copy this into the user key bindings, and replace all instances of ' with `.

+1

Now that JS supports template strings, this is fast become a must have feature. Even Atom has it.
It'd be preferable to not replace the single quote key binding.

+1

A bit late, but anyhow: There is no need to replace the single quote binding, just duplicate it and replace all the ' for ` on the block (there are three). As Gabe Muffington said, its implementable. Here is how it looks in mine, based on his advice:
(Default (Windows).sublime-keymap)

// Auto-pair single quotes

{ "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 - punctuation.definition.string.end", "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 },
{ "key": "selector", "operator": "not_equal", "operand": "punctuation.definition.string.begin", "match_all": true },
{ "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.single - punctuation.definition.string.end", "match_all": true },
]

}