Sublime Forum

How to & best way to enable auto closing for chars like <

#1

Hi,

sometimes I would like to auto-close the "Chevron"s (<). For example in C/C++ and some other moments. Is there a way to modify the behaviour? Or what would be the best way to do this manually? Write a global completion? If its not that easy I’d like to have a option with an array or charlist like word_separators has to specify globally which to auto-close and maybe context sensitive (depending on file type (< for c/c++ but not for html, xml), …)

Any idea? Opinions & help appreciated.

0 Likes

#2

Since angled braces are mostly used immediately after identifiers (or just text in general), you could easily make a keybinding for this that only triggers if there are certain conditions met, for example, being in a C/C++ file and the preceding character being non-whitespace.

For inspiration, you can take a look at the default bindings for auto-matching the other brace types.

0 Likes

#3

I was unable to find the default bindings so far. I tried searching in the Default.sublime.package.

But I made this which seems to work:

{"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 } ] }, {"keys": ["<"], "command": "insert_snippet", "args": {"contents": "<$SELECTION>"}, "context": [ { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true }, { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true } ] }

0 Likes