Search code examples
texttabstab-size

How do I force Sublime Text 2 to use a tab of 3 spaces in PHP files?


In some of my PHP files Sublime shows vertical lines (tab stops?) spaced 2 characters apart, and other files default to having these vertical lines at 3 characters apart (my preferred tab length).

Vertical lines can be seen below (these lines being 3 characters apart):

[Note I can't post a screenshot because I don't have enough points!]

My user preferences file is as follows:

{
    "draw_white_space": "none",
    "ignored_packages":
    [
        "Vintage"
    ],
    "tab_size": 3,
    "translate_tabs_to_spaces": true,
    "detect_indentation": false,
    "smart_indent": false,
    "use_tab_stops": false,
    "trim_trailing_white_space_on_save": true,
    "fallback_encoding": "UTF-8",
    "rulers": [80, 120]
}

I have tried different permutations of detect_indentation, smart_indent and use_tab_stops, i.e. totally omitting and true / false etc. This made no difference.

I'm really surprised that: a) There is inconsistency between different PHP files, i.e. some default to having vertical lines of 2 characters apart and others 3 characters apart. b) The user settings don't have the effect I expect.

Any Sublime Text 2 experts know how to get these vertical lines to default to my tab width setting?

Many thanks.


Solution

  • Because this refers to a syntax specifically in PHP, the settings have to be saved directly in a "Syntax Specific" settings file. Open the file Packages/User/PHP.sublime-settings in the packages folder and write the following:

    {
        "tab_size": 3,
        "translate_tabs_to_spaces": true,
        "detect_indentation": false
    }
    

    But if you want it to be like this for all your code (i.e. not just PHP), place it in the Packages/User/Preferences.sublime-settings file instead.