Bret Royster
Bret Royster

Reputation: 571

Specify a color scheme for specified file type

I want to use Monokai as my default Color Scheme.

For JSON files I want to use the Monokai JSON+ Color Scheme.

Question: How do I specify which color scheme to use for a specified file type?

Upvotes: 3

Views: 461

Answers (1)

OdatNurd
OdatNurd

Reputation: 22831

The color scheme used in Sublime is controlled by the color_scheme setting. If you select Preferences > Settings from the main menu, Sublime will open up a new window split down the middle vertically showing you two files.

The settings in the left hand side are the default settings that globally apply to everything in Sublime. The settings on the right hand side are your user specific settings.

Any setting you place in the right hand side overrides the default setting on the left, and any setting you don't specifically add to your custom preferences remains at the default.

For Sublime build 3143, the default value for the color_scheme is:

// Sets the colors used within the text area
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",

A small handful of settings in Sublime are application specific and can only be altered from the defaults in your user settings, an example of which is the theme setting that controls the overall look of the application.

For all other settings, you can further refine the settings that you want on a syntax (file type) basis, for example to alter how wide a tab is based on the type of the file that you're editing.

color_scheme is an example of setting that can be changed in this manner, allowing you to specify a color scheme other than the default for files of a certain type.

In order to do that, you first need to open up a file of the type whose settings you would like to change (in your example, that would be a JSON file). Make sure that the bottom right of the window is telling you that the file is of type JSON before you proceed.

Next, select, Preferences > Settings - Syntax Specific from the menu. Like the above command, this opens a new window that's split vertically, but this time your custom user settings are on the left and the settings specific to JSON are on the right (the file should be named JSON.sublime-settings).

Any settings that you add to this file will be in effect for any JSON file that you have open, with the rest of the settings behaving as they do above; if it appears in your user preferences, it will be set for JSON, and if it doesn't appear in your user preferences it will be set to the defaults.

So by adding the color_scheme setting specifically to that file, you can make your JSON files have a customized color scheme.

With all of that being said, the easiest way to change the global color scheme in Sublime Text 3143 is to use the Preferences > Color Scheme menu item, which allows you to interactively select the color scheme that you want to use.

There is no such menu item for specifically changing this setting on a per file basis. So if you're unfamiliar with settings in general, your best course of action to get a custom color scheme for a certain file type (JSON in this case) would be:

  1. Use Preferences > Color Scheme... to set the color scheme that you want to use for a particular file type (i.e. Monokai JSON + in your case)
  2. Open up a JSON file
  3. Select Preferences > Settings - Syntax Specific to open up the settings for JSON files
  4. Copy the color_scheme setting from the left hand pane to the right, then save the file
  5. Use Preferences > Color Scheme... to set the color scheme back to your global default.

As soon as you finish step #4, you should see the color scheme in your open JSON file change, letting you know that the operation has succeeded.

Upvotes: 2

Related Questions