在使用Visual Studio代码时,如何自定义制表符到空格的转换因子?
例如,现在在HTML中,每次按TAB键会产生两个空格,但在TypeScript中会产生4个空格。
在使用Visual Studio代码时,如何自定义制表符到空格的转换因子?
例如,现在在HTML中,每次按TAB键会产生两个空格,但在TypeScript中会产生4个空格。
当前回答
在Visual Studio Code版本1.14.1中
选择文件>首选项>设置/按[Ctrl +,]
选中“用户>常用” “Tab Size”设置为“4”
其他回答
当使用TypeScript时,默认的选项卡宽度总是2,不管它在工具栏中说什么。你必须设置“更漂亮”。tabWidth"在你的用户设置中更改它。
Ctrl + P,输入→用户设置,添加:
"prettier.tabWidth": 4
我们可以用EditorConfig和它的EditorConfig for VS Code扩展来控制文件类型的选项卡大小。然后,我们可以对每种文件类型使用Alt + Shift + F。
安装
用CTRL + P打开VS Code命令面板并粘贴如下:
ext install EditorConfig
示例配置
editorconfig。
[*]
indent_style = space
[*.{js,ts,json}]
indent_size = 2
[*.java]
indent_size = 4
[*.go]
indent_style = tab
settings.json
EditorConfig覆盖任何设置。Json为编辑器配置。不需要更改editor.detectIndentation。
我们亲爱的社区成员已经提供了很多很好的答案。我实际上想添加c#代码tabSize,并找到了这个线程。我找到了很多解决方案,官方VS Code文档很棒。我只是想分享我的c#设置:
"[csharp]": {
"editor.insertSpaces": true,
"editor.tabSize": 4
},
只需复制并粘贴上述代码到您的设置。Json文件并保存。谢谢
默认情况下,Visual Studio Code自动检测当前打开文件的缩进。如果您想关闭此功能并使所有缩进,例如,两个空格,您可以在用户设置或工作区设置中执行以下操作。
{
"editor.tabSize": 2,
"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