在使用Visual Studio代码时,如何自定义制表符到空格的转换因子?
例如,现在在HTML中,每次按TAB键会产生两个空格,但在TypeScript中会产生4个空格。
在使用Visual Studio代码时,如何自定义制表符到空格的转换因子?
例如,现在在HTML中,每次按TAB键会产生两个空格,但在TypeScript中会产生4个空格。
当前回答
我试着换编辑器。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,
}
如果这篇文章中接受的答案不奏效,试试这个:
我在编辑器中安装了用于Visual Studio Code的EditorConfig,它一直覆盖我的用户设置,这些设置被设置为使用空格缩进文件。每次我在编辑器选项卡之间切换时,我的文件都会自动用选项卡缩进,即使我已经将缩进转换为空格!!
在我卸载了这个扩展后,缩进不再改变切换编辑器选项卡之间,我可以更舒适地工作,而不是必须手动转换选项卡到空格每次我切换文件-这是痛苦的。
菜单文件→首选项→设置
添加到用户设置:
"editor.tabSize": 2,
"editor.detectIndentation": false
然后右键单击你的文档,如果你已经打开了一个,然后单击格式化文档,让你现有的文档遵循这些新的设置。
Note
如果你正在谈论tabSize的更漂亮,请参阅答案的第2部分
第一部分:VS代码方式
如果你喜欢开发人员的方式,Visual Studio Code允许你为tabSize指定不同的文件类型。下面是我的设置示例。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的新版本中),你可以:
左下档→ 设置→右上方打开设置
第二节:如果使用更漂亮
如果你使用的是prettier,情况可能会有所不同,prettier有两个级别的设置:
用户级别,你可以点击扩展和点击设置找到关键字tabWidth 项目级别,您可以从. pretierrc文件中的根项目级别添加/更新
User3550138正确。lonefy。vcode -js-css-html-formatter覆盖其他答案中提到的所有设置。但是,您不必禁用或卸载它,因为它可以配置。
可以通过打开扩展侧边栏并单击该扩展来找到完整的说明,它将在编辑器工作区中显示配置说明。至少在Visual Studio Code版本1.14.1中对我来说是这样的。