在我的项目中,我有TypeScript和HTML文件,在这两个文件中,选项卡都转换为空格。
我想关闭自动转换,并确保我的项目只有选项卡。
编辑:
通过这个设置,它似乎可以在HTML文件中工作,但不能在TypeScript文件中工作。
{
"editor.insertSpaces": false
}
在我的项目中,我有TypeScript和HTML文件,在这两个文件中,选项卡都转换为空格。
我想关闭自动转换,并确保我的项目只有选项卡。
编辑:
通过这个设置,它似乎可以在HTML文件中工作,但不能在TypeScript文件中工作。
{
"editor.insertSpaces": false
}
当前回答
如果你想用制表符而不是空格
试试这个:
进入文件➤偏好设置,或者按Ctrl +, 在顶部的搜索设置栏中插入editor.insertSpaces 你会看到这样的东西:编辑器:插入空格,它可能会被选中。只要取消它如下图所示
重载Visual Studio Code(按F1➤输入重载窗口➤按Enter)
如果行不通,试试这个:
这可能是因为安装了插件JS-CSS-HTML Formatter
(你可以点击文件➤偏好设置➤扩展项,或者按Ctrl + Shift + X,在Enabled列表中你会找到JS-CSS-HTML Formatter)
如果是这样,你可以修改这个插件:
按F1➤输入Formatter config➤按Enter(它会打开Formatter .json文件) 修改文件如下:
4| "indent_size": 1,
5| "indent_char": "\t"
——|
24| "indent_size": 1,
25| "indentCharacter": "\t",
26| "indent_char": "\t",
——|
34| "indent_size": 1,
35| "indent_char": "\t",
36| "indent_character": "\t"
保存(进入文件➤保存或按Ctrl + S) 重载Visual Studio Code(按F1➤输入重载窗口➤按Enter)
其他回答
下面的设置对我来说很好,
"editor.insertSpaces": false,
"editor.formatOnSave": true, // only if you want auto fomattting on saving the file
"editor.detectIndentation": false
上述设置将反映并应用于每个文件。你不需要手动缩进/格式化每个文件。
从官方的vscode设置中检查:
// Controls whether `editor.tabSize#` and `#editor.insertSpaces` will be automatically detected when a file is opened based on the file contents.
"editor.detectIndentation": true,
// The number of spaces a tab is equal to. This setting is overridden based on the file contents when `editor.detectIndentation` is on.
"editor.tabSize": 4,
// Config the editor that making the "space" instead of "tab"
"editor.insertSpaces": true,
// Configure editor settings to be overridden for [html] language.
"[html]": {
"editor.insertSpaces": true,
"editor.tabSize": 2,
"editor.autoIndent": false
}
如果你想在很多文件中将制表符更改为空格,但又不想单独打开它们,我发现只使用最左侧工具栏中的“查找和替换”选项同样有效。
在第一个框(Find)中,从源代码中复制并粘贴一个选项卡。
在第二个框(Replace)中,输入您希望使用的空格数(即2或4)。
如果你按…按钮,你可以指定目录包含或忽略(即src/Data/Json)。
最后,检查结果预览并按“全部替换”。工作区中的所有文件都可能受到影响。
突出显示你的代码(在文件中) 单击应用程序窗口右下角的标签大小 选择适当的将缩进转换为制表符
文件->首选项->设置或只需按Ctrl +,并搜索空格,然后只需禁用此选项:
我必须重新打开文件,这样更改才能生效。