在使用Visual Studio代码时,如何自定义制表符到空格的转换因子?
例如,现在在HTML中,每次按TAB键会产生两个空格,但在TypeScript中会产生4个空格。
在使用Visual Studio代码时,如何自定义制表符到空格的转换因子?
例如,现在在HTML中,每次按TAB键会产生两个空格,但在TypeScript中会产生4个空格。
当前回答
如果这是针对Angular 2的,并且CLI正在生成你想要不同格式的文件,你可以编辑这些文件来改变生成的内容:
npm_modules/@angular/cli/blueprints/component/files/__path__/*
不推荐大量的npm更新,因为它会删除你的工作,但它为我节省了很多时间。
其他回答
一个更简单的方法是使用Visual Studio Code提供的内置通配符过滤器@lang:。
步骤
点击设置图标(左下) 选择设置 在搜索设置输入框中输入@lang:javascript tabsize
这将过滤所有的设置,只留下javascript的tabSize选项。输入您想要的tab因子,它将应用于该语言。
请注意 要将这些设置应用到用户配置文件,请确保选择了user选项卡。如果选择Workspace选项卡,VSCode将在你的项目文件夹中创建一个带有设置的. VSCode文件夹。json文件;这意味着您所做的任何更改都只应用于当前工作空间(项目文件夹) 你可以将它用于任何其他语言,例如@lang:php tabsize
默认情况下,Visual Studio Code将根据您打开的文件尝试猜测缩进选项。
你可以通过"editor.detectIndentation": false关闭缩进猜测。
您可以通过以下三个设置轻松自定义:Windows菜单中的文件→首选项→用户设置,Mac菜单中的代码→首选项→设置或⌘,:
// 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
菜单文件→首选项→设置
添加到用户设置:
"editor.tabSize": 2,
"editor.detectIndentation": false
然后右键单击你的文档,如果你已经打开了一个,然后单击格式化文档,让你现有的文档遵循这些新的设置。
我试着换编辑器。tabSize改为4,但是. editorconfig将覆盖我所指定的任何设置,因此不需要更改用户设置中的任何配置。你只需要编辑.editorConfig文件:
set indent_size = 4
在Visual Studio Code版本1.14.1中
选择文件>首选项>设置/按[Ctrl +,]
选中“用户>常用” “Tab Size”设置为“4”