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

2

5

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.

Overcapitalize answered 22/2, 2013 at 7:53 Comment(1)
One thing that can cause some confusion here is that it seems that Sublime only does the indentation detection on a file open operation and will maintain the detected value until the file tab is closed. If you set "detect_indentation" to false, you probably need to close all tabs and reopen them, otherwise you may have some files observing the previously detected value.Gurtner
N
10

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.

Nivernais answered 25/2, 2013 at 0:36 Comment(1)
Thanks for your response, it really helped me out :)Overcapitalize
T
1

The both methods are valids, but I think that you should know about the file Preferences.sublime-settings, this are the default preferences for all enviroment.

You can acess Preferences.sublime-settings going to:

Prefenrences > Setting - Default

on the main menu. Or accessing the path:

/home/<user_name>/.config/sublime-text-3/Packages/Default/Preferences.sublime-settings

for Linux Users, but at others operatings systems have arquitecture similar, except by the particularities of access to directories. Like Windowns C:\\Programs Files\Sublime Text 3\[...]

The file Preferences.sublime-settings already have many paramters pre-difined and you just need to assign values ​​to your liking. The range of possible values, ​​in general, are true, false or numeric.

For you case you should change the values of "tab_size", by default it receive 4 spaces as value - It's perfect for Python programmers), simply change to the desired value.

// Set to true to turn spell checking on by default
"spell_check": false,

// 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": true,

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

The settings that I always like of change the value are:

"translate_tabs_to_spaces": true, //prevents that to switch from editor the indentation be changed.

"highlight_line": true, //highlights the line where the course is.

"auto_complete_commit_on_tab": true, //allows complement of code structure with tab key.
Truncheon answered 20/10, 2013 at 10:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.