在使用Visual Studio代码时,如何自定义制表符到空格的转换因子?
例如,现在在HTML中,每次按TAB键会产生两个空格,但在TypeScript中会产生4个空格。
在使用Visual Studio代码时,如何自定义制表符到空格的转换因子?
例如,现在在HTML中,每次按TAB键会产生两个空格,但在TypeScript中会产生4个空格。
当前回答
默认情况下,Visual Studio Code自动检测当前打开文件的缩进。如果您想关闭此功能并使所有缩进,例如,两个空格,您可以在用户设置或工作区设置中执行以下操作。
{
"editor.tabSize": 2,
"editor.detectIndentation": false
}
其他回答
我试着换编辑器。tabSize改为4,但是. editorconfig将覆盖我所指定的任何设置,因此不需要更改用户设置中的任何配置。你只需要编辑.editorConfig文件:
set indent_size = 4
我不得不像之前的答案一样做了很多设置编辑,所以我不知道在做了很多修改后它能正常工作。
在我关闭并打开我的IDE之前没有任何工作,但我所做的最后三件事是禁用lonefy。html.format vscode-js-css-html-formatter。”enable": true,并重新启动Visual Studio。
{
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"workbench.colorTheme": "Default Light+",
"[html]": {
"editor.defaultFormatter": "vscode.html-language-features",
"editor.tabSize": 2,
"editor.detectIndentation": false,
"editor.insertSpaces": true
},
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": true,
"editor.tabSize": 2,
"typescript.format.insertSpaceAfterConstructor": true,
"files.autoSave": "afterDelay",
"html.format.indentHandlebars": true,
"html.format.indentInnerHtml": true,
"html.format.enable": true,
"editor.detectIndentation": false,
"editor.insertSpaces": true,
}
User3550138正确。lonefy。vcode -js-css-html-formatter覆盖其他答案中提到的所有设置。但是,您不必禁用或卸载它,因为它可以配置。
可以通过打开扩展侧边栏并单击该扩展来找到完整的说明,它将在编辑器工作区中显示配置说明。至少在Visual Studio Code版本1.14.1中对我来说是这样的。
我们亲爱的社区成员已经提供了很多很好的答案。我实际上想添加c#代码tabSize,并找到了这个线程。我找到了很多解决方案,官方VS Code文档很棒。我只是想分享我的c#设置:
"[csharp]": {
"editor.insertSpaces": true,
"editor.tabSize": 4
},
只需复制并粘贴上述代码到您的设置。Json文件并保存。谢谢
在你的右下角,有空格: 空间:2
在这里你可以根据你的需要改变缩进: 缩进的选项