每当我让 vscode 自动格式化我的代码时,它都会格式化为 2 个空格而不是 4 个空格,尽管显然默认值是 4 个空格,而且我还没有触及 settings.json
Editor.tabsize 也显示 4。
在右下角,它显示空格:4,但自动格式化后,它显示空格:2,并且无论我将其更改为4多少次,它都会恢复为2。
任何人都知道发生了什么事。 Ruby 正在发生这种情况,如果这很重要的话。
另外,有人知道 VScode 的替代压痕器/自动格式化程序吗?
我认为您可能对“自动检测缩进”有问题。您应该尝试将其关闭,看看是否有帮助。
// 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
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
indent_style = tab
indent_size = 4
end_of_line = crlf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
确保还安装了 VS Code 扩展!
另一个对我有用的解决方案: