Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text 3: 4 spaces for tab not working only for javascript files

in Sublime Text 3 I have 4 tab spaces in User Preferences. This is the part of settings file:

{
    ...

    // 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,

    ...
}

It works good except for Javascript files, where the tab spaces are 2. I do not understand why.

Any help?

I tried to create Javascript specific setting file, but it didn't work either.

like image 487
Giacomo M Avatar asked Nov 08 '22 08:11

Giacomo M


1 Answers

I faced the same issue. The problem occurs if you open an existing file which has tab set as 2 spaces ( Files loaded from GitHub mostly have this ). On the other hand, if you create a new .js file, the tab is set as 4 as instructed.

As mentioned by @OdatNurd, you have "detect_indentation" set to True. This detects the indentation of loaded file.

like image 88
Sarath M Avatar answered Nov 14 '22 21:11

Sarath M