Sublime Forum

Insert smart quotes into Sublime

#1

I need to be able to insert smart (curly) quotes into a document I am doing for work. Can someone perhaps guide me as to how to do this in sublime. I would require both single and double smart quotes.

0 Likes

#2

I was able to find this article on curly quotes https://typographyforlawyers.com/straight-and-curly-quotes.html
I followed the instructions for Windows and it worked on ST, though it seems to have to press 4 keys to actually do it.

0 Likes

#3

Thank you. I don’t mind pressing four keys. Unfortunately, it just so happens that the 0 on my numpad key does not work. :<. If I press 0 on my main keyboard I get ô

0 Likes

#4

Have you looked at this post?

0 Likes

#5

I have not but I will look at it and revert back.

0 Likes

#6

I could not get this to work for me, but then I am a new user of Sublime. I think it is simplest if I just use straight quotes. I’m not sure the effort is worth my while. Thanks in any event.

0 Likes

#7

For some reason there were some [ missing in the code. Copy the code below, go to Preferences -> Key bindings, and paste on the right hand side pane. I haven’t tested fully, but it seems to work.

		/*** Smart Double Quotes (“”) ***/
		// Surround selection with smart quotes // OK, I think
		{ "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 },
				{ "key": "selector", "operator": "equal", "operand": "text", "match_all": true }
			]
		},
		// Auto-pair smart quotes // OK -- but what about following/preceding regexs?
		{ "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 }, // does commenting it out alter anything?
				{ "key": "selector", "operator": "equal", "operand": "text", "match_all": true }
			]
		},
		// Smart quote before word
		{ "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": "reg ex_contains", "operand": "^\\S", "match_all": true },
				{ "key": "following_text", "operator": "not_regex_contains", "operand": "^(“|”|‘|’|\\)|])", "match_all": true },
				{ "key": "selector", "operator": "equal", "operand": "text", "match_all": true }
			]
		},
		// Smart quote after word
		{ "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": "preceding_text", "operator": "regex_contains", "operand": "\\S$", "match_all": true },
				{ "key": "following_text", "operator": "not_regex_contains", "operand": "^(“|”|‘|’|\\)|])", "match_all": true },
				{ "key": "selector", "operator": "equal", "operand": "text", "match_all": true }
			]
		},
		// Do not overwrite smart quotes with dumb quotes // OK, I think
		{ "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": "equal", "operand": "text", "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 },
				{ "key": "selector", "operator": "equal", "operand": "text", "match_all": true }
			]
		},
		/*** Smart Single Quotes (‘’) ***/
		// Surround selection with smart quotes // OK, I think
		{ "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 },
				{ "key": "selector", "operator": "equal", "operand": "text", "match_all": true }
			]
		},
		// Auto-pair smart quotes // OK -- but what about following/preceding regexs?
		{ "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 }, // does commenting it out alter anything?
				{ "key": "selector", "operator": "equal", "operand": "text", "match_all": true }
			]
		},
		// Smart quote before word
		{ "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": "^\\S", "match_all": true },
				{ "key": "following_text", "operator": "not_regex_contains", "operand": "^(“|”|‘|’|\\)|])", "match_all": true },
				{ "key": "selector", "operator": "equal", "operand": "text", "match_all": true }
			]
		},
		// Smart quote after word
		{ "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": "preceding_text", "operator": "regex_contains", "operand": "\\S$", "match_all": true },
				{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "(“|‘)$", "match_all": true },
				// { "key": "following_text", "operator": "not_regex_contains", "operand": "^(“|”|‘|’|\\)|])", "match_all": true },
				{ "key": "following_text", "operator": "not_regex_contains", "operand": "^(“|‘|’|\\)|])", "match_all": true },
				{ "key": "selector", "operator": "equal", "operand": "text", "match_all": true }
			]
		},
		// Do not overwrite smart quotes with dumb quotes // OK, I think
		{ "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": "equal", "operand": "text", "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 },
				{ "key": "selector", "operator": "equal", "operand": "text", "match_all": true }
			]
		},
1 Like