- 按下
Ctrl + Shift + P
(Windows/Linux)或Cmd + Shift + P
(Mac)来打开命令面板。 - 输入open settings,然后选择 Open User Settings(JSON)。打开
settings.json
文件
------修改设置-----:
1、 html代码的行长度, 避免格式化时换行
html
"editor.wordWrap": "on",
"editor.wordWrapColumn": 2000, // 设置为你想要的最大行长度
"html.format.wrapAttributes": "auto",
"html.format.wrapLineLength": 2000, // 设置为你想要的最大行长度
Formatting
To improve the formatting of your HTML source code, you can use the Format Document command ⇧⌥F to format the entire file or Format Selection ⌘K ⌘F to just format the selected text.
The HTML formatter is based on js-beautify. The formatting options offered by that library are surfaced in the VS Code settings:
- html.format.wrapLineLength: Maximum amount of characters per line.
- html.format.unformatted: List of tags that shouldn't be reformatted.
- html.format.contentUnformatted: List of tags, comma separated, where the content shouldn't be reformatted.
- html.format.extraLiners: List of tags that should have an extra newline before them.
- html.format.preserveNewLines: Whether existing line breaks before elements should be preserved.
- html.format.maxPreserveNewLines: Maximum number of line breaks to be preserved in one chunk.
- html.format.indentInnerHtml: Indent
<head>
and<body>
sections. - html.format.wrapAttributes: Wrapping strategy for attributes:
auto
: Wrap when the line length is exceededforce
: Wrap all attributes, except firstforce-aligned
: Wrap all attributes, except first, and align attributes 强制所有属性对其force-expand-multiline
: Wrap all attributesaligned-multiple
: Wrap when line length is exceeded, align attributes verticallypreserve
: Preserve wrapping of attributespreserve-aligned
: Preserve wrapping of attributes but align
- html.format.wrapAttributesIndentSize: Alignment size when using
force aligned
andaligned multiple
in html.format.wrapAttributes ornull
to use the default indent size. - html.format.templating: Honor django, erb, handlebars and php templating language tags.
- html.format.unformattedContentDelimiter: Keep text content together between this string.
Tip: The formatter doesn't format the tags listed in the html.format.unformatted and html.format.contentUnformatted settings. Embedded JavaScript is formatted unless 'script' tags are excluded.
The Marketplace has several alternative formatters to choose from. If you want to use a different formatter, define "html.format.enable": false
in your settings to turn off the built-in formatter.