Sublime Forum

Recognize the ` character as a type of a quotation

#1

After selecting an entire word or phrase and then hitting a quotation character once, the selection will be enclosed in appropriate quotation marks. This neat functionality works for the " quote and the ’ quote, but it currently does not work for the ` quote, which is sometimes quite necessary in MySQL statements, so it would be nice if that one worked as well.

0 Likes

#2

Add the following to your user key bindings:

[code]
{ “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 }
]

},
{ “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”: “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 }
]

}[/code]

1 Like

#3

Heureka it works!

Thanks mate :smiley:

0 Likes

#4

Taking a moment to update the formatting on the above code because it looks like a few open brackets have been stripped:

{
	"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 
		}
	]
},
{
	"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": "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
		}
	]
},
0 Likes

#5

Btw, posts can now be selected as an answer.

1 Like