Sublime Text 3 HTML auto indent issue

sublime-text-3

I just started using Sublime Text 3. I noticed an annoying auto un-indent that happens when writing HTML and I can't figure out how to prevent it.

Any time I write html like this:

<div class="myclass">

</div>

And then follow it up by moving my cursor in between the open and closing div, it auto indents correctly and places the cursor one indent into the tag block like this (imagine the pipe character is the cursor):

<div class="myclass">
    |
</div>

But then as soon as I type the opening bracket for the nested element, the cursor jumps back one indent space like this (again, the pipe character is the cursor):

<div class="myclass">
<|
</div>

I can't figure out what setting is causing this or how to prevent it. The only plugin I've installed is SFTP and Package Control. Is this a beta bug or is there some setting that's causing this un-indenting?

Best Answer

I can reproduce this on OSX using the latest build 3053 when I type the opening div, hit Enter twice, close the div, go back up a line, and hit Tab to position the cursor for another tag. However, there is a way around it: type the first div element, then immediately type </ and the tag will auto-close. Move your cursor back between the opening and closing tag, and hit Enter. You'll end up with your cursor like so:

<div class="myclass">
    |
</div>

and you can start typing another tag without the problematic behavior occurring - Sublime takes care of the auto-indenting for you. Besides, I like to close my tags as soon as I open them, just so I don't forget - I'm easily distracted :) However, once your cursor is indented, don't hit Backspace and then Tab again, or the same problem will happen.

No, I don't know where to report a bug for the beta, except by posting in the forum. It was down for me too the other day, but it seems to be working as I write this. I just posted the bug, so hopefully somebody can do something about it.

Happy coding!

Related Question