Visual studio code Visual Studio代码-将空格转换为选项卡
我的项目中有TypeScript和HTML文件,在这两个文件中,选项卡都转换为空格 我想关闭自动转换,并确保我的项目只有选项卡 编辑: 使用此设置,它似乎可以在HTML文件中工作,但不能在TypeScript文件中工作Visual studio code Visual Studio代码-将空格转换为选项卡,visual-studio-code,tabs,spaces,Visual Studio Code,Tabs,Spaces,我的项目中有TypeScript和HTML文件,在这两个文件中,选项卡都转换为空格 我想关闭自动转换,并确保我的项目只有选项卡 编辑: 使用此设置,它似乎可以在HTML文件中工作,但不能在TypeScript文件中工作 { “editor.insertSpaces”:false } 在.vscode/settings.json中有3个选项: // The number of spaces a tab is equal to. "editor.tabSize": 4, // Insert spa
{
“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)
更新:
现在您可以手动编辑这些选项了
单击编辑器右下角的选择器空格:4:
如果要将现有ws-to-tab转换为,请从Marketplace安装扩展
编辑:
要将现有缩进从空格转换为制表符,请按Ctrl++ 并键入:
>Convert indentation to Tabs
这将根据定义的选项卡设置更改文档的缩进。要更改选项卡设置,请单击vscode窗口右下角状态栏中Ln/Col文本右侧的文本区域
名称可以是选项卡大小
或空格
将弹出一个包含所有可用操作和设置的菜单
在我的例子中,问题是在1月份更新后安装了扩展名JS-CSS-HTML格式化程序。默认的缩进字符属性是空格。我卸载了它,奇怪的行为停止了。下面的设置对我来说很好
"editor.insertSpaces": false,
"editor.formatOnSave": true, // only if you want auto fomattting on saving the file
"editor.detectIndentation": false
上述设置将反映并应用于每个文件。您不需要手动缩进/格式化每个文件。Ctrl+Shift+p,然后“将缩进转换为制表符”从官方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
}
如果要使用制表符而不是空格
试试这个:
转到文件
➤ 首选项
➤ 设置
或只需按Ctrl+,
在顶部的搜索设置栏中插入编辑器。插入空间
您将看到如下内容:编辑器:插入空格,它可能会被选中。只需取消选中它,如下图所示
重新加载Visual Studio代码(按F1
➤ 键入重新加载窗口
➤ 按进入)
如果不起作用,请尝试以下方法:
这可能是因为安装了插件JS-CSS-HTML格式化程序
(您可以通过转到文件
➤ 首选项
➤ 扩展
或只需按Ctrl++,在启用列表中,您将找到JS-CSS-HTML格式化程序)
如果是,您可以修改此插件:
按F1➤ 键入格式化程序配置
➤ 按Enter键(它将打开文件formatter.json
)
文件
➤ 保存
或只需按Ctrl+重新加载窗口
➤ 按进入)True
适用于我。如果您想将许多文件中的制表符更改为空格,但不想单独打开它们,我发现只需使用最左侧工具栏中的查找和替换选项同样适用
在第一个框(Find
)中,复制并粘贴源代码中的选项卡
在第二个框(Replace
)中,输入希望使用的空格数(即2或4)
如果按…
按钮,可以指定要包括或忽略的目录(即src/Data/Json
)
最后,检查结果预览并按“全部替换”。工作区中的所有文件都可能受到影响。哦,是的,这是我的实际问题。花大量时间在VS代码中修改设置。最后,禁用此扩展解决了问题。对我来说,这只会更改当前查看的特定文件的这些设置。项目中的其他文件保留其旧设置。如果需要的话,我通常一次替换所有文件,方法是搜索简单的正则表达式`{4}`并替换为\t(用于制表符)。通常还会浏览匹配项,以确保没有任何内容会像多行字符串文字等那样中断。显然,应用这些设置,以便您的新缩进也是所需的字符!如果需要空格而不是制表符,请修改
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"
{
"editor.insertSpaces": true
}