如何将 VSCode 更改为缩进 4 个空格而不是默认的 2 个? [英] How do I Change VSCode To Indent 4 Spaces Instead Of Default 2?
问题描述
我在 VS Code 中应用了以下设置以获得 4 个空格缩进.
但总是当我打开一个新文件时,它会切换回右下角的 2.
I have applied the below settings in VS Code to get 4 spaces indentation.
But always when I open a new file, it switches back to 2 in the right-bottom corner.
如果我点击右下角的 并将设置改回 4,
VSCode 仍然会变回 2 并仍然使用 2 空格自动缩进来应用它.
Alt+Shift+F
If I click in the right-bottom corner and change the setting back to 4,
VSCode will still change back to 2 and still apply it with the 2-space auto-indent.
Alt+Shift+F
我错过了什么?
推荐答案
有点迟到的答案.但是刚刚解决了同样的问题...
Bit of an late answer. But just got the same issue solved...
很多东西都可以控制这一点.它也花了我相当多的实验来纠正它.对我来说,下面的第 3 点是让它发挥作用的最后一个技巧.在此之前,我注意到编辑器加载了 4 个,但跳回了 2 个空格.现在保持在 4.
Multiple things are able to control this. It also has taken me quite a bit of experimentation to get it corrected. For me point 3 below was the final trick to make it work. Before that, I noticed the editor loading with 4, but jumping back to 2 spaces. Now it stays at 4.
需要检查的一些事项:
Some things to check:
1:VS Code 配置(设置和工作区,您可以为系统范围配置或仅针对当前工作区设置这些):检查您是否已设置:
1: VS Code configuration (Settings & Workspace, you can set these for system wide configuration or just for the current Workspace): Check whether you have set:
"editor.tabSize": 4,
"editor.insertSpaces": true,
"editor.detectIndentation": false
和语言特定设置(可选):
And language specific settings (optional):
"[javascript]": {
"editor.tabSize": 4
},
"[typescript]": {
"editor.tabSize": 4
}
2: 是否有任何可能影响缩进的扩展 -> 人们已经报告 JS-CSS-HTML 也配置设置.
2: Are there any Extensions that could influence the indentation -> people have reported JS-CSS-HTML to also configure the setting.
3:您的工作区中是否有 .editorconfig 文件?如果是这样,请检查那里的设置.例如,Angular 创建一个并配置 indent_size:
3: Is there a .editorconfig file in your workspace? If so, check the settings over there. Angular creates one for example and configures the indent_size:
# Editor configuration, see http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
max_line_length = off
trim_trailing_whitespace = false
大多数答案都集中在第 1 点,但对我来说,最后一步对于使 VS Code 正常工作很重要.
Most answers focussed point 1 which, but for me the last step was important to make VS Code work properly.
此 Stack Overflow 以不同的答案处理上述所有内容:Visual Studio Code:格式未使用缩进设置
This Stack Overflow handles all of the above in different answers: Visual Studio Code: format is not using indent settings
这篇关于如何将 VSCode 更改为缩进 4 个空格而不是默认的 2 个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!