在使用Visual Studio代码时,如何自定义制表符到空格的转换因子?
例如,现在在HTML中,每次按TAB键会产生两个空格,但在TypeScript中会产生4个空格。
在使用Visual Studio代码时,如何自定义制表符到空格的转换因子?
例如,现在在HTML中,每次按TAB键会产生两个空格,但在TypeScript中会产生4个空格。
当前回答
如果这篇文章中接受的答案不奏效,试试这个:
我在编辑器中安装了用于Visual Studio Code的EditorConfig,它一直覆盖我的用户设置,这些设置被设置为使用空格缩进文件。每次我在编辑器选项卡之间切换时,我的文件都会自动用选项卡缩进,即使我已经将缩进转换为空格!!
在我卸载了这个扩展后,缩进不再改变切换编辑器选项卡之间,我可以更舒适地工作,而不是必须手动转换选项卡到空格每次我切换文件-这是痛苦的。
其他回答
默认情况下,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
如果您在Visual Studio Code中使用更漂亮的扩展,请尝试将此添加到设置中。json文件:
"editor.insertSpaces": false,
"editor.tabSize": 4,
"editor.detectIndentation": false,
"prettier.tabWidth": 4,
"prettier.useTabs": true // This made it finally work for me
在你的右下角,有空格: 空间:2
在这里你可以根据你的需要改变缩进: 缩进的选项
我运行的是版本1.21,但我认为这也适用于其他版本。
看看屏幕的右下角。您应该看到显示空格或制表符大小的内容。
我的是空格→
点击空格(或Tab-Size) 选择“使用空格缩进”或“使用制表符缩进” 选择所需的空格或制表符数量。
这只适用于每个文档,而不是整个项目。如果你想在项目范围内应用它,你还需要在你的用户设置中添加"editor.detectIndentation": false。
如果这是针对Angular 2的,并且CLI正在生成你想要不同格式的文件,你可以编辑这些文件来改变生成的内容:
npm_modules/@angular/cli/blueprints/component/files/__path__/*
不推荐大量的npm更新,因为它会删除你的工作,但它为我节省了很多时间。