Syntax specific settings in sublime-project settings file

﹥>﹥吖頭↗ 提交于 2021-02-07 06:51:18

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/19904581/syntax-specific-settings-in-sublime-project-settings-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!