在Visual Studio Code中使用Format Code命令时,它不尊重我的缩进设置(“editor. exe”)。tabSize": 2).它使用的是4的标签大小。知道为什么会这样吗?

谢谢!


当前回答

如果@Maleki的答案不适合你,检查一下你的项目文件夹中是否有。editorconfig文件。

例如,Angular CLI会生成一个这样的新项目

# Editor configuration, see http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false

更改这里的indent_size是必需的,因为它似乎会覆盖你的.vscode工作区或用户设置中的任何内容。

其他回答

还要确保你的工作区设置没有覆盖你的用户设置。用户界面并没有很明显地显示你正在编辑哪些设置,“文件>首选项>设置”默认为用户设置,即使工作空间设置胜过用户设置。

你也可以直接编辑工作区设置:/.vscode/settings.json

我认为vscode默认使用autopep8来格式化.py。

PEP 8——Python代码风格指南| Python.org

根据这个网站,下面可以解释为什么vscode总是使用4个空格。

每个缩进层使用4个空格。

在我的情况下,VScode使用更漂亮的包来格式化我的代码。

我是如何解决的:

右击代码-> Format Selection With -> Change Default Formatter -> TypeScript和Javascript语言特性

像往常一样在VScode中设置选项卡首选项。

如果@Maleki的答案不适合你,检查一下你的项目文件夹中是否有。editorconfig文件。

例如,Angular CLI会生成一个这样的新项目

# Editor configuration, see http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false

更改这里的indent_size是必需的,因为它似乎会覆盖你的.vscode工作区或用户设置中的任何内容。

VSCode插件Vetur;用于VueJS应用程序正在覆盖我的设置。

将vetr .format.options. tabsize设置为我喜欢的空格数就可以工作了。