在使用Visual Studio代码时,如何自定义制表符到空格的转换因子?
例如,现在在HTML中,每次按TAB键会产生两个空格,但在TypeScript中会产生4个空格。
在使用Visual Studio代码时,如何自定义制表符到空格的转换因子?
例如,现在在HTML中,每次按TAB键会产生两个空格,但在TypeScript中会产生4个空格。
当前回答
User3550138正确。lonefy。vcode -js-css-html-formatter覆盖其他答案中提到的所有设置。但是,您不必禁用或卸载它,因为它可以配置。
可以通过打开扩展侧边栏并单击该扩展来找到完整的说明,它将在编辑器工作区中显示配置说明。至少在Visual Studio Code版本1.14.1中对我来说是这样的。
其他回答
在Visual Studio Code版本1.31.1或更高版本中(我认为):像sed Alex Dima一样,您可以通过这些设置轻松地自定义
Windows菜单中的文件→首选项→用户设置或使用短键Ctrl + Shift + P Mac在菜单代码→首选项→设置或⌘,
默认情况下,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
我试着换编辑器。tabSize改为4,但是. editorconfig将覆盖我所指定的任何设置,因此不需要更改用户设置中的任何配置。你只需要编辑.editorConfig文件:
set indent_size = 4
我运行的是版本1.21,但我认为这也适用于其他版本。
看看屏幕的右下角。您应该看到显示空格或制表符大小的内容。
我的是空格→
点击空格(或Tab-Size) 选择“使用空格缩进”或“使用制表符缩进” 选择所需的空格或制表符数量。
这只适用于每个文档,而不是整个项目。如果你想在项目范围内应用它,你还需要在你的用户设置中添加"editor.detectIndentation": false。
菜单文件→首选项→设置
添加到用户设置:
"editor.tabSize": 2,
"editor.detectIndentation": false
然后右键单击你的文档,如果你已经打开了一个,然后单击格式化文档,让你现有的文档遵循这些新的设置。