Yuval Adam
Yuval Adam

Reputation: 165232

Syntax specific settings in sublime-project settings file

A sublime-settings file enforces settings on a per-project basis:

{
    "folders": [ ... ]
    "settings":
    {
        "tab_size": 4
    }
}

How is it possible to use syntax specific settings in this file, for example to set a tab_size of 2 only for *.js files?

Upvotes: 6

Views: 3597

Answers (2)

ariamckinley
ariamckinley

Reputation: 1122

You could checkout .editorconfig.

Basically an .editorconfig file would look like,

# editorconfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,py}]
charset = utf-8

# 4 space indentation
[*.py]
indent_style = space
indent_size = 4

# Tab indentation (no size specified)
[Makefile]
indent_style = tab

# Indentation override for all JS under lib directory
[lib/**.js]
indent_style = space
indent_size = 2

# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2

There's even a nice Sublime Text package that automatically reads and understands them. Just throw your .editorconfig in version control and you're ready to go.

Upvotes: 4

angerson
angerson

Reputation: 7402

You can't set language-exclusive settings directly in your user Preferences.sublime-settings file. However, when editing a file of a given type, you can create a settings file limited only to that type with the menu item Preferences -> Settings–More -> Syntax Specific – User.

This new file will appear in your Packages/User directory with a name matching its language, e.g. Markdown.sublime-settings would be a Markdown-specific settings file.

Upvotes: 3

Related Questions