简体   繁体   中英

VS Code: auto format html does not work

In VS Code I am having trouble in formatting HTML.

For example, I write a list of tags inline and I press Shift + Alt + F and nothing happens.

I noticed this:

If I write:

<div><span><p></p></span></div> 

nothing happens when I do the auto format.

If I write:

<div><div><div></div></div></div>

then it becomes:

<div>
    <div>
        <div></div>
    </div>
</div>

hope this will help you to help me...

We had the same problem in my dev team. Please check or try the following things:

  • Are the keyboard bindings correct?
  • Is selected code language HTML?
  • Have you restarted VS code?
  • Begin a small piece of the formatting and then try again (for some reason it thinks its already correct.

There are a certain list of tags that are ignored when auto formatting - these are defined in the setings.json file under

html.format.unformatted":

So go to settings (Command-Comma on a mac) and search for that setting and remove the tags you do want formatting.

The bad news is that it still doesn't format how I think it should - ie the isn't indented inside the but it at least puts it on a new line for you!

This is a VS code bug. I installed the 1.17 and it worked very well https://code.visualstudio.com/updates/v1_17

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM