在 VSCode 中自动缩进 <head> 和 <body>

Autoindent <head> and <body> in VSCode

VSCode 的格式化程序默认不缩进 <head><body> 标签。在默认设置中存在以下行:

// Indent <head> and <body> sections.
"html.format.indentInnerHtml": false,

我尝试将用户设置中的 html.format.indentInnerHtml 设置为 true,但没有任何改变。

这是我得到的:

<html>

<head></head>

<body></body>

</html>

这就是我想要的:

<html>

    <head></head>

    <body></body>

</html>

我安装了 "JS-CSS-HTML Formatter" 扩展,这是导致问题的原因。卸载后一切正常。

File/Preferences/Settings

或快捷方式

Ctrl+逗号

并将html.format.indentInnerHtml更改为true

{
  "html.format.indentInnerHtml": true
}

本网站上更多有用的设置

https://code.visualstudio.com/docs/languages/html#_formatting