我的项目中既有TypeScript文件又有HTML文件,在这两个文件中,都将制表符转换为空格。
我想关闭自动转换,并确保我的项目只有制表符。
编辑:
通过此设置,HTML文件似乎可以正常工作,但TypeScript文件不行。
{
"editor.insertSpaces": false
}
我的项目中既有TypeScript文件又有HTML文件,在这两个文件中,都将制表符转换为空格。
我想关闭自动转换,并确保我的项目只有制表符。
编辑:
通过此设置,HTML文件似乎可以正常工作,但TypeScript文件不行。
{
"editor.insertSpaces": false
}
.vscode/settings.json
中有3个选项:
// The number of spaces a tab is equal to.
"editor.tabSize": 4,
// Insert spaces when pressing Tab.
"editor.insertSpaces": true,
// When opening a file, `editor.tabSize` and `editor.insertSpaces` will be detected based on the file contents.
"editor.detectIndentation": true
editor.detectIndentation
检测文件缩进,您需要禁用它。 如果没有帮助,请检查您是否有更高优先级的设置。 例如,当将其保存到用户设置中时,它可能会被项目文件夹中的工作区设置覆盖。更新:
要访问这些设置,可以打开文件»首选项 »设置,单击左下角的管理图标,或使用键盘快捷键:CTRL+,(Windows,Linux);⌘+,(Mac)。
更新:
现在你有一种替代方法来手动编辑这些选项。单击编辑器底部的选择器Spaces:4:
编辑:
要将现有缩进从空格转换为制表符,请按Ctrl+Shift+P,然后键入:
>Convert indentation to Tabs
这将根据定义的设置将您的文档缩进更改为制表符。
{4}
进行项目搜索,并用\t(制表符)进行替换。通常还会浏览匹配项,以确保不会出现多行字符串字面值等问题。显然,应用这些设置,使您的新缩进也是所需的字符! - cossacksmanCtrl+Shift+P,然后选择 "将缩进转换为制表符"
文件
➤ 首选项
➤ 设置
或者直接按下 Ctrl + ,editor.insertSpaces
F1
➤ 输入 reload window
➤ 按下 Enter)这可能是由于安装了插件JS-CSS-HTML Formatter导致的。
(你可以通过前往文件
➤ 首选项
➤ 扩展
或者直接按下 Ctrl + Shift + X 检查,你将在启用的列表中找到JS-CSS-HTML Formatter)
如果是这样,你可以修改这个插件:
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)reload window
➤ 按下 Enter)formatter.json
文件:在任何引号中放入一个 _空格_,而不是 \t
(所以 " \t "
变成了 " "
),并在看到 1 的地方放置 4。因此您的文件可能会像这样:
"indent_size": 4, "indent_char": " " "indent_size": 4, "indentCharacter": " ", "indent_char": " ", "indent_size": 4, "indent_char": " ", "indent_character": " "
- Alex Logvin请查看官方的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
}
indent_char
属性是空格。我卸载了它,奇怪的行为就停止了。"editor.insertSpaces": false,
"editor.formatOnSave": true, // only if you want auto fomattting on saving the file
"editor.detectIndentation": false
如果你使用 .sass
文件出现了 Expected tabs, was spaces
错误,请将此设置为 false
:
"editor.detectIndentation": false
...然后选择你的代码块,按下tab
键进行缩进,再按下shift + tab
键进行反缩进。