// 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
好吧,如果您喜欢开发人员的方式,Visual Studio Code允许您为tabSize指定不同的文件类型。这是我的settings.json示例,默认为四个空格,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 Code中),您可以:
如果您在Visual Studio Code中使用更漂亮的扩展,请尝试将其添加到settings.json文件中:
"editor.insertSpaces": false,"editor.tabSize": 4,"editor.detectIndentation": false,
"prettier.tabWidth": 4,"prettier.useTabs": true // This made it finally work for me