Home Download Buy Blog Forum Support

autoclose html tags (sublime 2)

autoclose html tags (sublime 2)

Postby matias on Tue Oct 11, 2011 7:52 am

is there any plugin to autoclose html elements? for example: as i type <html> this tag need to be closed as </html> automatically.

thank you.
matias
 
Posts: 3
Joined: Tue Oct 11, 2011 7:17 am

Re: autoclose html tags (sublime 2)

Postby bizoo on Tue Oct 11, 2011 7:59 am

In a recent build:
Menu: Edit -> Tag -> Close Tag (Alt+.)
bizoo
 
Posts: 859
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: autoclose html tags (sublime 2)

Postby matias on Tue Oct 11, 2011 8:26 am

bizoo wrote:In a recent build:
Menu: Edit -> Tag -> Close Tag (Alt+.)


yes, but i need this to be closed automatically. pressing alt+. is the manual way i think?
matias
 
Posts: 3
Joined: Tue Oct 11, 2011 7:17 am

Re: autoclose html tags (sublime 2)

Postby iamntz on Tue Oct 11, 2011 8:50 am

You can try to bind the close tag command to > or </ shortcut.
iamntz
 
Posts: 819
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania

Re: autoclose html tags (sublime 2)

Postby bizoo on Tue Oct 11, 2011 9:17 am

Actually typing something like:
Code: Select all
div

followed by TAB key automatically expand to:
Code: Select all
<div></div>
bizoo
 
Posts: 859
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: autoclose html tags (sublime 2)

Postby tito on Wed Oct 12, 2011 2:22 am

There is plugin
https://github.com/kihlstrom/Close-Tag- ... blime-Text
That automatically calls to "Edit -> Tag -> Close Tag (Alt+.)" when hitting "</" there is a pull request waiting to add support for multiples regions.
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 708
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Re: autoclose html tags (sublime 2)

Postby grayrest on Wed Oct 12, 2011 3:01 am

Here's what I have in User:

keys:
Code: Select all
   // Auto close tags
   { "keys": [">"], "command": "auto_close_tag", "args": { "prefix": ">"}, "context":
      [
         { "key": "selector", "operator": "equal", "operand": "text.html meta.tag -string -punctuation.definition.tag.begin.html -meta.scope.between-tag-pair.html, text.xml meta.tag -string -punctuation.definition.tag.begin.xml -meta.scope.between-tag-pair.xml", "match_all": true },
         { "key": "preceding_text", "operator": "not_regex_contains", "operand": "(?:\\<(?:img|br|hr|meta|link|base|input)\\>[^<]*)|/$" }
      ]
   },
   // Line and Tab when hitting enter between tags   
   { "keys": ["enter"], "command": "insert_snippet", "args": {"contents": "\n\t$0\n"}, "context":
      [
         { "key": "setting.auto_indent", "operator": "equal", "operand": true},
         { "key": "selector", "operator": "equal", "operand": "meta.scope.between-tag-pair"}
      ]
   },


autoclose_tags.py:
Code: Select all
import sublime, sublime_plugin

class AutoCloseTagCommand(sublime_plugin.TextCommand):
    def run(self, edit, prefix=""):
        self.view.run_command('insert', {'characters': prefix})
        cursorPosition = self.view.sel()[0].begin()
        self.view.run_command('close_tag')
        self.view.sel().clear()
        self.view.sel().add(cursorPosition)
grayrest
 
Posts: 12
Joined: Thu Sep 29, 2011 5:03 pm

Re: autoclose html tags (sublime 2)

Postby supervova on Thu Nov 22, 2012 7:35 am

grayrest wrote:Here's what I have in User:

autoclose_tags.py:


Great stuff, man. Many thanks
supervova
 
Posts: 1
Joined: Thu Nov 22, 2012 7:30 am

Re: autoclose html tags (sublime 2)

Postby bunyamin on Tue Nov 12, 2013 9:14 am

grayrest wrote:Here's what I have in User:

keys:....
autoclose_tags.py:
Code: Select all
import sublime, sublime_plugin
...


Dude, you're awesome. Thanks!
bunyamin
 
Posts: 1
Joined: Sun Nov 10, 2013 9:08 am

Re: autoclose html tags (sublime 2)

Postby solepixel on Fri Mar 28, 2014 9:39 pm

Is it possible to alter this to remove the closing tag if backspace is pressed on the >?
So example would be
<option> would produce <option>|</option>
single backspace would return to: <option|

Another example:
<a|
<a>|</a>
<a|
<abbr|
<abbr>|</abbr>

Make sense?
solepixel
 
Posts: 1
Joined: Fri Mar 28, 2014 9:35 pm


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 18 guests

cron