如何在Visual Studio Code中更改缩进?

问题描述:

对于每个打字稿文件,Visual Studio代码都使用8个空格的自动缩进.这对我来说有点太多了,但是我找不到更改它的地方.

For every typescript file visual studio code uses an auto indentation of 8 spaces. This is a bit too much for my taste but I can't find where to change it.

也许它可以作为设置使用,但使用其他名称,因为我找不到与缩进有关的任何东西.

Maybe it's available as a setting but under a different name as I can't find anything related to indentation.

更新

我目前正在使用更高级的代码格式化程序,它可以解决通过保存时自动格式化来解决所有格式化问题(如果没有语法错误)

I'm currently using the Prettier code formatter and that solves all formatting problems by auto formatting on save (if there is no syntax error)

您可以在全局User级别或Workspace级别进行更改.

You can change this in global User level or Workspace level.

打开设置:使用快捷键 Ctrl 或单击File> Preferences> Settings如下所示.

Open the settings: Using the shortcut Ctrl , or clicking File > Preferences > Settings as shown below.

然后,进行以下两项更改:(在搜索栏中键入tabSize)

Then, do the following 2 changes: (type tabSize in the search bar)

  1. 取消选中Detect Indentation
  2. 的复选框
  3. 将制表符大小更改为2/4(尽管我强烈认为2对JS是正确的:))
  1. Uncheck the checkbox of Detect Indentation
  2. Change the tab size to be 2/4 (Although I strongly think 2 is correct for JS :))