Visual studio 代码的编辑器配置

editorconfig for Visual studio code

我的项目有 .editorconfig 文件:

[*.{js}]
charset = utf-8
indent_style = space
indent_size = 4

我认为这会强制我的 VS Code 使用缩进样式 space 和 4 spaces。

我从扩展列表中安装了 EditorConfig for vs code 扩展。

但仍然没有,我新创建的文件不会自动设置配置的 space 样式。有什么问题?

尝试

root = true
[*.js]
indent_style = space
indent_size = 4
charset = utf-8

这个也可以试试,喜欢可以换空格:)

root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = tab
indent_size = 2

[*.{js,txt,md,css,html,php,py,json,yml,sass,pug}]
indent_style = tab
indent_size = 2

[*.{diff,md}]
trim_trailing_whitespace = false

VS Code需要插件才能使用editorconfig,所以需要安装插件

我想我找到了解决办法。当我通过右键单击 VSCode 和 select Generate .editorconfig 中的文件夹结构侧栏创建 .editorconfig(从而让插件创建它)时,它起作用了。

点击文件下方的空白区域: