使用Visual Studio代码时,如何自定义tab-to-space转换因子?
例如,现在在HTML中,它似乎每次按
默认情况下,Visual Studio代码将根据打开的文件尝试猜测缩进选项。
您可以通过
您可以通过以下三个设置轻松地对Windows进行自定义:菜单中的“文件首选项”用户设置;菜单中的“代码首选项”设置或:
// The number of spaces a tab is equal to. This setting is overridden
// based on the file contents when `editor.detectIndentation` is true.
"editor.tabSize": 4,
// Insert spaces when pressing Tab. This setting is overriden
// based on the file contents when `editor.detectIndentation` is true.
"editor.insertSpaces": true,
// When opening a file, `editor.tabSize` and `editor.insertSpaces`
// will be detected based on the file contents. Set to false to keep
// the values you've explicitly set, above.
"editor.detectIndentation": false
我运行的是1.21版本,但我想这可能也适用于早期版本。
请看一下屏幕的右下角。您应该看到
我的显示空间,
这只适用于每个文档,而不适用于整个项目。如果要在项目范围内应用它,还需要将
如果您喜欢开发人员的方式,Visual Studio代码允许您为
{
// I want my default to be 4, but JavaScript/JSON to be 2
"editor.tabSize": 4,
"[javascript]": {
"editor.tabSize": 2
},
"[json]": {
"editor.tabSize": 2
},
// This one forces the tab to be **space**
"editor.insertSpaces": true
}
PS:嗯,如果您不知道如何打开此文件(特别是在新版本的Visual Studio代码中),您可以:
 ;