Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime 2 -changing background color based on file type?

Tags:

sublimetext2

Using an existing Sublime 2 color scheme, is there a way to tweak the background color selectively for eg. .js files only? Many thanks!

like image 320
Silver Dragon Avatar asked Feb 28 '13 13:02

Silver Dragon


2 Answers

You have to modify your .tmTheme color scheme plist. You can find it with menu Preferences/Browse Packages..., Color Scheme - Default directory.

You should add something like this:

<dict>
    <key>scope</key>
    <string>source.js</string>
    <key>settings</key>
    <dict>
        <key>background</key>
        <string>#000000</string>
    </dict>
</dict>

as a child of the settings array (of course you have to change #000000 with your color code).

like image 118
Riccardo Marotti Avatar answered Nov 03 '22 01:11

Riccardo Marotti


I was actually trying to change the background color for text files and was wondering how Riccardo figured out how to use source.js as the value for the scope.

You need to locate the .tmLanguage file of the file type you are trying to change, which is "Plain text.tmLanguage" for text files. Then look for the scopeName key and use the value for that. This is from my "Plain text.tmLanguage" file:

<key>scopeName</key>
<string>text.plain</string>

So, for example, to change the foreground color for text files to lime:

<dict>
        <key>scope</key>
        <string>text.plain</string>
        <key>settings</key>
        <dict>
            <key>foreground</key>
            <string>#00FF00</string>
        </dict>
    </dict>
like image 22
Dean Avatar answered Nov 02 '22 23:11

Dean