javascript - 崇高文本 3 : 4 spaces for tab not working only for javascript files

标签 javascript sublimetext3 indentation

在 Sublime Text 3 中,我在用户首选项中有 4 个制表位。这是设置文件的一部分:

{
    ...

    // The number of spaces a tab is considered equal to
    "tab_size": 4,

    // Set to true to insert spaces when tab is pressed
    "translate_tabs_to_spaces": false,

    // If translate_tabs_to_spaces is true, use_tab_stops will make tab and
    // backspace insert/delete up to the next tabstop
    "use_tab_stops": true,

    // Set to false to disable detection of tabs vs. spaces on load
    "detect_indentation": 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,

    ...
}

它工作得很好,除了 Javascript 文件,其中的制表符空格是 2。我不明白为什么。

有什么帮助吗?

我试图创建 Javascript 特定的设置文件,但它也不起作用。

最佳答案

我遇到了同样的问题。如果您打开一个将选项卡设置为 2 个空格的现有文件(从 GitHub 加载的文件大多有这个),则会出现问题。另一方面,如果您创建一个新的 .js 文件,则按照说明将选项卡设置为 4。
正如@OdatNurd 所述,您将“detect_indentation”设置为True。这会检测加载文件的缩进。

关于javascript - 崇高文本 3 : 4 spaces for tab not working only for javascript files,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39676572/

相关文章:

Javascript 未定义、truthy 与 typeof 运算符

javascript - 当父级来自不同域时,在另一个 iframe 中执行 javascript 函数

command - Sublime Text 3 - 自定义命令 - 将文本添加到元素

c++ - 如何在 macOS 上的 Sublime Text 3 上自动运行 C++11?

javascript - 仅针对特定文件禁用 JSHint 缩进检查

javascript - 为什么 Javascript 显示错误的日期?

sublimetext3 - 在 Sublime Text 3 中使用新编码保存打开的文件

ruby-on-rails - 缩进 Ruby on Rails 代码的正确样式是什么?

android-studio - 安卓工作室 "This file is indented with tabs instead of 4 spaces"

javascript - 'window.open' 被 Chrome 阻止并发生更改事件