AntonJH
AntonJH

Reputation: 113

Visual Studio Code Auto close tag and indent XML as with HTML

I've started using Visual Studio Code for HTML and CSS as it, in my opinion, seems to be a nice editor (except for this little issue). When I started using it, I had to get an extension to get automatic closing tags. All the extensions I've found seem to do this the same way: (| = cursor)

<p>|</p>

When I type the '>' in the start tag, I get the closing tag, which is what I want. Though when I hit Enter, it does this:

<p>
|</p>

This is, as far as I think, basically useless as I then have to hit Enter one more time, then up-arrow and then TAB... I mean, it's not like the closing tag is ever supposed to be at the end of the line on a multi-line element.

On a happier note though, VS code now has native support for automatic closing tags in HTML like this:

<p>|</p>

=>

<p>
  |
</p>

(Moves the closing tag down one line and indents the empty line with the cursor on it.) This is exactly what I want and I don't ever wanna live without it. (Thanks VS Code!)

My current problem though begun when I started writing XML... VS Code doesn't help me there for some reason, even though XML and HTML looks exactly the same! So I've looked around for auto close tag extensions and the ones I find are still like the old ones:

<p>
|</p>

So not only do I have useless auto close tags for XML, I then have a different system for HTML. This is, to say the least, very irritating.

So I guess, after all this ranting my question is something like: Is there any way to get VS Code to help me with XML the same way it does with HTML? Maybe change something somewhere so that it accepts XML. Or maybe there is some wonderful extension hid under some carpet somewhere that I haven't found...?

I really appreciate any help I can get! Thank you!

Upvotes: 5

Views: 12293

Answers (2)

Fred Bricon
Fred Bricon

Reputation: 5589

Auto-close and auto-indent are supported by Red Hat's XML extension for VS Code. enter image description here

Upvotes: 4

Mark
Mark

Reputation: 183094

If you click on the "XML" in the lower right of the window - next to the line ending - and choose "Configure file association for .xml" and choose HTML you will get the same indenting behavior as in html files.

Upvotes: 13

Related Questions