Sublime Forum

Autoclosing angle brackets?

#1

Hello everyone,
I just love Sublime Text 2, great features, very customisable, but for some reason a very important feature (at least for me it is) is missing and that is autoclosing angle brackets.
You might be thinking of auto closing tags, but what I’m looking for is different, by the way it is a feature found in Textmate, as soon as I type an angle bracket < I’d love for sublime to put a > right after it. This can be extended to when I type <? it closes with ?>, same with ruby tags <% and it puts %>.

Are you aware of a plugin that does that or is it a preference to enable? I’ve looked in the docs, nothing found.

Thanks in advance

Jeremy a.k.a. Visudex

0 Likes

Auto-close angled brackets in Sublime Text 3
#2

Put this into your keybinding file:
(works only on html files)


	{ "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.double", "match_all": true },
			{ "key": "selector", "operator": "equal", "operand": "text.html" },
			{ "key": "selector", "operator": "not_equal", "operand": "source.php" }
		]
	},
	{ "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.html" },
			{ "key": "selector", "operator": "not_equal", "operand": "source.php" }
		]
	},
	{ "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.html" },
			{ "key": "selector", "operator": "not_equal", "operand": "source.php" }
		]
	},
		{ "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.html" },
			{ "key": "selector", "operator": "not_equal", "operand": "source.php" }
		]
	},
	{ "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.html" },
			{ "key": "selector", "operator": "not_equal", "operand": "source.php" }
		]
	}
0 Likes

#3

Thanks a lot.

0 Likes

#4

Any idea of how one can adjust this to work with LaTeX as well?

0 Likes

#5

See the html selector lines:

{ "key": "selector", "operator": "equal", "operand": "text.html" },

Change each operand to “text.html, text.latex” (or whatever the base scope of latex is).

0 Likes