VSCode autoformat转到2个空格而不是4个

Chr*_*Lai 2 visual-studio-code

每当我让vscode autoformat我的代码时,它格式化为2个空格而不是4个,即使显然默认是4个空格,我还没有触及settings.json

Editor.tabsize也显示4.

在右下角,它显示空格:4,但在autoformatting之后,它显示空格:2,无论我将其更改为4多少次,它都会恢复为2.

任何人都知道发生了什么.如果这很重要,Ruby就会发生这种情况.

另外,有没有人知道VScode的备用压头/ autoformatter?

Sam*_*ami 19

对于那些像我一样无法使用上述内容的人,这里有一些 GUI 指南。

按=> CTRL+ ,(评论建议)打开设置或通过菜单进入设置

File->Preferences->Settings   
Run Code Online (Sandbox Code Playgroud)

您可以在搜索框中找到(查找tab sizedetect indentation),如下图所示(请参阅文本“让我们玩”)

detect indentation=> 取消选中它(关闭)

tab size=> 将其设置为 4

如何 ?需要可视化吗?这里是,

右键单击下面的图像并在新选项卡中打开看清楚

在此输入图像描述


小智 8

我认为您可能遇到"自动检测缩进"问题.您应该尝试将其关闭,看看是否有帮助.

// The number of spaces a tab is equal to. This setting is overriden based on the file contents when `editor.detectIndentation` is on.
"editor.tabSize": 4,

// When opening a file, `editor.tabSize` and `editor.insertSpaces` will be detected based on the file contents.
"editor.detectIndentation": false
Run Code Online (Sandbox Code Playgroud)

  • 我从心底里讨厌这个 IDE。两个小时了,我无法解决这个问题...我将文件缩进了 4 个空格,当我点击自动格式化快捷方式时,它又回到了 2 个空格...我不知道到底发生了什么... (3认同)
  • @LachezarRaychev - 您可能安装了一个扩展,例如 Prettier,它会覆盖 VSCode 的内置设置。找到该扩展的配置并在那里配置您的缩进设置。 (3认同)