5

I'm using Sublime Text 2, and I'm sure there must be a way to make it auto-close XML/HTML tags, the way for example Notepad++ can.

Is there a way to have it add </div> immediately after I type <div>?

4 Answers 4

7

As zoli's answer states, you can use snippets/completions to auto complete tags as you start typing them. But there should be some built into sublime. For example, as you start to type <div>, you should see a drop down box with matching snippets. Hit Tab or Enter to pick one and arrow keys to go up or down in the list. For html tags, it will automatically adds the closing tag and puts the cursor in between them.

Another option is: use Edit > Tag > Close Tag. The hotkeys are displayed in the file menu. It automatically adds the closing tag if you already added an opening tag.

5

Sublime's built-in snippets differ for HTML and XML.

For HTML, you can type <div then Tab to autocomplete <div></div>.

For XML, though, it's different. You first type < then Tab to autocomplete to <p></p> with the p tags multiple-selected by default. So you can then type foo and have it autocomplete to <foo></foo>. Once you've named your element, you can press Tab to jump to the content of the element.

You can use Edit > Tag > Close Tag equally on both HTML and XML.

3

SublimeCodeIntel has pretty good completions for HTML. You can type a tag name (w/o the opening brace) and press Tab to complete both the opening and closing tag.

0

Use the Emmet plugin.

To create a closed div, simply type div then press the Tab key.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .