Home Download Buy Blog Forum Support

Autoclosing angle brackets?

Autoclosing angle brackets?

Postby visudex on Mon Sep 12, 2011 3:50 pm

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
visudex
 
Posts: 2
Joined: Mon Sep 12, 2011 3:43 pm

Re: Autoclosing angle brackets?

Postby iamntz on Mon Sep 12, 2011 3:54 pm

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

   { "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" }
      ]
   }
iamntz
 
Posts: 915
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania

Re: Autoclosing angle brackets?

Postby visudex on Mon Sep 12, 2011 3:58 pm

Thanks a lot.
visudex
 
Posts: 2
Joined: Mon Sep 12, 2011 3:43 pm

Re: Autoclosing angle brackets?

Postby holene on Wed Oct 02, 2013 10:40 am

Any idea of how one can adjust this to work with LaTeX as well?
holene
 
Posts: 17
Joined: Mon Jun 25, 2012 8:33 am

Re: Autoclosing angle brackets?

Postby FichteFoll on Sun Oct 06, 2013 8:48 pm

See the html selector lines:

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


Change each operand to "text.html, text.latex" (or whatever the base scope of latex is).
FichteFoll
 
Posts: 402
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 17 guests