在使用Visual Studio代码时,如何自定义制表符到空格的转换因子?
例如,现在在HTML中,每次按TAB键会产生两个空格,但在TypeScript中会产生4个空格。
在使用Visual Studio代码时,如何自定义制表符到空格的转换因子?
例如,现在在HTML中,每次按TAB键会产生两个空格,但在TypeScript中会产生4个空格。
当前回答
在Visual Studio Code版本1.31.1或更高版本中(我认为):像sed Alex Dima一样,您可以通过这些设置轻松地自定义
Windows菜单中的文件→首选项→用户设置或使用短键Ctrl + Shift + P Mac在菜单代码→首选项→设置或⌘,
其他回答
我不得不像之前的答案一样做了很多设置编辑,所以我不知道在做了很多修改后它能正常工作。
在我关闭并打开我的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,
}
菜单文件→首选项→设置
添加到用户设置:
"editor.tabSize": 2,
"editor.detectIndentation": false
然后右键单击你的文档,如果你已经打开了一个,然后单击格式化文档,让你现有的文档遵循这些新的设置。
评论如下:
有没有办法改变每一种语言的tabSize ?例如,当在同一个工作区中编辑多个不同语言的文件时(如Ruby, JavaScript, CSS等)- Ruby将是2个空格,但CSS将是4个…通常
这就是为什么,VSCode 1.63(2021年11月),你有:
多种语言特定的编辑器设置 现在,您可以一次为多种语言配置特定于语言的编辑器设置。 下面的例子展示了如何同时自定义javascript和typescript语言的设置: “[javascript](打印稿)":{ “编辑器。maxTokenizationLineLength”:2500 }
在你的情况下:
"[ruby][html]": {
"editor.insertSpaces": true,
"editor.tabSize": 2
},
"[csharp][typescript]": {
"editor.insertSpaces": true,
"editor.tabSize": 4
},
你也可以在终端中改变制表符的大小,使用VSCode 1.75(2023年1月)。
你想要确保你的编辑配置不与你的用户或工作区设置配置冲突,因为我只是有一点烦恼,认为设置文件设置没有被应用时,它是我的编辑器配置撤消这些更改。
User3550138正确。lonefy。vcode -js-css-html-formatter覆盖其他答案中提到的所有设置。但是,您不必禁用或卸载它,因为它可以配置。
可以通过打开扩展侧边栏并单击该扩展来找到完整的说明,它将在编辑器工作区中显示配置说明。至少在Visual Studio Code版本1.14.1中对我来说是这样的。