【问题标题】:Sublime Text is not converting tabs to spaces when indenting... why and how to fix it?Sublime Text 在缩进时不会将制表符转换为空格......为什么以及如何解决它?
【发布时间】:2014-04-30 00:57:50
【问题描述】:

我一直在非常有效地使用 Sublime 文本。我有一个问题仍然困扰着我。

当我键入 JavaScript 代码时,如果 tab 在提供的缩进级别之外被按下,则制表符不会转换为空格。

下面的截图可以帮助你理解我的问题:

如您所见,缩进的初始级别正确格式化为 8 个空格。如果我再次按 tab,则会插入一个实际的制表符,而不是我想要的 4 个空格。

以下是我的用户Preferences.sublime-settings配置文件:

{
"color_scheme": "Packages/User/Cobalt (SL).tmTheme",
"detect_indentation": false,
"expand_tabs_on_save": true,
"font_size": 10,
"ignored_packages":
[
    "Vintage"
],
"tab_size": 4,
"translate_tabs_to_spaces": true,
"trim_automatic_white_space": true,
"use_tab_stops": true,

// Calculates indentation automatically when pressing enter
"auto_indent": true,

// Makes auto indent a little smarter, e.g., by indenting the next line
// after an if statement in C. Requires auto_indent to be enabled.
"smart_indent": true,

// Adds whitespace up to the first open bracket when indenting. Requires
// auto_indent to be enabled.
"indent_to_bracket": false,

// Trims white space added by auto_indent when moving the caret off the
// line.
"trim_automatic_white_space": true,

}

配置似乎设置正确。知道为什么会发生这种情况以及如何解决吗?

【问题讨论】:

  • 嗯,作为一个快速的健全性检查,你能告诉我view.settings().get("translate_tabs_to_spaces") 的结果吗?此外,您的首选项中有一个额外的逗号。 ST 处理它,但只是想如果你没有看到它,我会告诉你。
  • @skuroda,感谢您的建议。对不起,我只能在这个星期五回来工作。然后,我会尝试你的建议并回复。
  • view.settings().get("translate_tabs_to_spaces") 正在返回 False
  • 这意味着某些东西正在改变该文件中的设置。它可以是插件,也可以是 ST 设置。在我们开始使用插件之前,请尝试在您的用户首选项文件中将 detect_indentation 设置为 false
  • 嗯,这有点令人失望(因为我希望这将是一个简单的解决方案)。右下角是“空格”还是“制表符”?您是否为 JavaScript 文件创建了任何自定义设置?你能列出你已经安装的插件吗?

标签: tabs indentation sublimetext sublimetext3 spaces


【解决方案1】:

有时 smart_indent 会搞砸事情。尝试将以下行添加到 Preferences>Settings-User

"smart_indent": false

【讨论】:

    猜你喜欢
    • 2014-04-27
    • 2020-01-05
    • 2013-01-24
    • 2012-03-17
    • 1970-01-01
    • 2014-01-07
    • 1970-01-01
    • 2020-02-23
    相关资源
    最近更新 更多