提问者:小点点

如何自定义tab-to-space转换系数?


使用Visual Studio代码时,如何自定义tab-to-space转换因子?

例如,现在在HTML中,它似乎每次按生成两个空格,但在TypeScript中,它生成4个空格。


共3个答案

匿名用户

默认情况下,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版本,但我想这可能也适用于早期版本。

请看一下屏幕的右下角。您应该看到的内容。

我的显示空间,

  1. 选择使用空格缩进或使用制表符缩进/li>
  2. 选择所需的空格或制表符数量。/li>

这只适用于每个文档,而不适用于整个项目。如果要在项目范围内应用它,还需要将添加到用户设置中。

匿名用户

如果您喜欢开发人员的方式,Visual Studio代码允许您为指定不同的文件类型。下面是我的的示例,默认有四个空格,JavaScript/JSON有两个空格:

{
  // 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代码中),您可以:

 ;