Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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>?

share|improve this question
up vote 6 down vote accepted

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

Use the Emmet plugin.

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

share|improve this answer

You must log in to answer this question.

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