在使用Visual Studio代码时,如何自定义制表符到空格的转换因子?
例如,现在在HTML中,每次按TAB键会产生两个空格,但在TypeScript中会产生4个空格。
在使用Visual Studio代码时,如何自定义制表符到空格的转换因子?
例如,现在在HTML中,每次按TAB键会产生两个空格,但在TypeScript中会产生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,
}
其他回答
@ alexo -dima从2015年开始的解决方案将改变所有文件的制表符大小和空格,@Tricky从2016年开始的解决方案似乎只改变当前文件的设置。
截至2017年,我找到了另一种针对每种语言的解决方案。Visual Studio Code没有为Elixir使用合适的标签大小或空间设置,所以我发现我可以更改所有Elixir文件的设置。
我点击状态栏中的语言(在我的例子中是“Elixir”),选择“Configure 'Elixir' language based settings…”,并编辑Elixir特定的语言设置。我只是复制了“编辑器”。tabSize和编辑器。“insertSpaces”设置从左边的默认设置(我很高兴显示这些设置),然后在右边修改它们。
它工作得很好,现在所有Elixir语言文件都使用了适当的制表符大小和空间设置。
我试着换编辑器。tabSize改为4,但是. editorconfig将覆盖我所指定的任何设置,因此不需要更改用户设置中的任何配置。你只需要编辑.editorConfig文件:
set indent_size = 4
如果这是针对Angular 2的,并且CLI正在生成你想要不同格式的文件,你可以编辑这些文件来改变生成的内容:
npm_modules/@angular/cli/blueprints/component/files/__path__/*
不推荐大量的npm更新,因为它会删除你的工作,但它为我节省了很多时间。
我们亲爱的社区成员已经提供了很多很好的答案。我实际上想添加c#代码tabSize,并找到了这个线程。我找到了很多解决方案,官方VS Code文档很棒。我只是想分享我的c#设置:
"[csharp]": {
"editor.insertSpaces": true,
"editor.tabSize": 4
},
只需复制并粘贴上述代码到您的设置。Json文件并保存。谢谢
User3550138正确。lonefy。vcode -js-css-html-formatter覆盖其他答案中提到的所有设置。但是,您不必禁用或卸载它,因为它可以配置。
可以通过打开扩展侧边栏并单击该扩展来找到完整的说明,它将在编辑器工作区中显示配置说明。至少在Visual Studio Code版本1.14.1中对我来说是这样的。