Visual Studio代码中的选项卡空格

Mat*_*yev 106 tabs spaces typescript visual-studio-code

我写作TypeScriptHTML文件,标签变成了空格.这是我第一次使用Visual Studio Code.

我试图更改设置并重新启动,但没有任何改变.

我配置的设置:

{
  "editor.insertSpaces": false
}
Run Code Online (Sandbox Code Playgroud)

我想谷歌它,我发现我做了正确的一步,当我加入TypeScript.html,但它不改变我的喜好...

编辑1:

我发现标签工作在.ts文件中,但不是TypeScript文件...

v-a*_*rew 184

有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
Run Code Online (Sandbox Code Playgroud)

.vscode/settings.json从您的文件中检测到它,您必须禁用它.如果没有帮助,请检查您没有更高优先级的设置.例如,当您将其保存到用户设置时,它可能会被项目文件夹中的工作区设置覆盖.

更新:
现在您可以手动编辑这些选项.
单击编辑器右下角的选择器Spaces:4:
Ln44,Col. [空间:4]. 带BOM的UTF-8. CTRLF. HTML. :)

如果要将现有ws转换为制表符,请从Marketplace安装扩展程序
编辑:
要将现有缩进从空格转换为标签命中editor.detectIndentation和键入:

>Convert indentation to Tabs
Run Code Online (Sandbox Code Playgroud)

这将根据Tabs的已定义设置更改文档的缩进.

  • 如何为 VSCode 中的所有文件和项目永久“>将缩进转换为制表符”? (13认同)
  • 如何对工作区中的所有文件运行此命令。 (3认同)

Eri*_*sot 122

要更改选项卡设置,请单击vscode窗口右下方状态栏中Ln/Col文本右侧的文本区域.

名称可以是Tab SizeSpaces.

将弹出一个菜单,其中包含所有可用的操作和设置.

在此输入图像描述

  • 对我来说,这只会更改我当前正在查看的特定文件的这些设置。项目中的其他文件保留其旧设置。您将如何普遍设置它? (2认同)

car*_*org 22

按Ctrl + shift + P然后"将缩进转换为制表符"


Ale*_*vin 11

如果要使用制表符而不是空格

尝试这个:

  1. FilePreferencesSettings或按Ctrl + ,
  2. 在顶部的搜索设置栏中editor.insertSpaces
  3. 您将看到类似以下内容的内容:编辑器:插入空格,可能会选中它。只需取消选中它,如下图所示

编辑器:插入空格

  1. 重新加载Visual Studio代码(按F1?输入reload window?按Enter

如果不起作用,请尝试以下操作:

可能是因为安装了JS-CSS-HTML Formatter插件

(你可以去检查FilePreferencesExtensions或只是按Ctrl + Shift + X,在启用名单,你会发现JS-CSS-HTML格式化

如果是这样,您可以修改此插件:

  1. F1?类型Formatter config?按Enter(它将打开文件formatter.json
  2. 像这样修改文件:
 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"
Run Code Online (Sandbox Code Playgroud)
  1. 保存(转到FileSave或按Ctrl + S
  2. 重新加载Visual Studio代码(按F1?输入reload window?按Enter

  • “重新加载窗口”步骤是我所缺少的。令人沮丧的是,我已经检查了复选框并摆弄了 3 次设置,却没有进行任何更改,而我所要做的就是重新加载窗口。谢谢你的提示! (2认同)

小智 9

  1. 突出显示您的代码(在文件中)
  2. 单击应用程序窗口右下角的选项卡大小 应用程序窗口图像右下角的选项卡大小
  3. 选择适当的将缩进转换为制表符 选择适当的将缩进转换为制表符图像


Vin*_*res 8

就我而言,问题是在1月更新后安装了JS-CSS-HTML Formatter扩展.默认的indent_char属性是空格.我卸载它并且奇怪的行为停止了.


Roh*_*mar 6

以下设置对我来说效果很好,

"editor.insertSpaces": false,
"editor.formatOnSave": true, // only if you want auto fomattting on saving the file
"editor.detectIndentation": false
Run Code Online (Sandbox Code Playgroud)

以上设置将反映并应用于每个文件.您无需手动缩进/格式化每个文件.


lam*_*345 6

文件->首选项->设置或只需按Ctrl+,并搜索空格,然后停用此选项:

在此输入图像描述

我必须重新打开该文件以使更改生效。


Xin*_*Xin 5

从官方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,

// Configure editor settings to be overridden for [html] language.
"[html]": {
    "editor.insertSpaces": true,
    "editor.tabSize": 2,
    "editor.autoIndent": false
}
Run Code Online (Sandbox Code Playgroud)