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

谢谢!


当前回答

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

我是如何解决的:

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

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

其他回答

Visual Studio Code检测每个默认值的当前缩进并使用它——忽略.editorconfig

同时将"editor.detectIndentation"设置为false

(文件->首选项->设置)

以上两种解决方案都不适合我,所以我在我的整个用户文件夹中搜索文件中的“tabSize”。最终,我在“设置”中找到了一个覆盖我的设置的选项,并且总是适用于(新)打开的文件:

"[python]": {
    "editor.detectIndentation": false,
    "editor.insertSpaces": true,
    "editor.tabSize": 4
},

下面的设置解决了我的问题

  "editor.detectIndentation": false,
  "editor.insertSpaces": false,
  "editor.tabSize": 2,

禁用所有插件(然后逐个启用并验证)

我有一个“。editorconfig”文件在父目录(ionic项目)的值“indent_size = 2”,它确实覆盖了我为我的工作空间选择的任何值! 我一改,问题就解决了。