Sublime Forum

Change Color Scheme Depending On File Type Open

#1

I have a color scheme that I want to open for all .cfm files. But for .js files, I want the default Cobalt. In the same window, is there a way to switch to a specific Color Theme depending on the file I’m looking at (open)?

Thanks!

1 Like

#2

You can do this in the “Syntax Specific - User” file under the preferences menu.

0 Likes

#3

Thanks. Yeap, I can get to that file, but it comes up blank. What code do I put in there so that:

if I have a .cfm file open, switch to color scheme x
if I have a .js file open, switch to color scheme y
if I have a .pl file open, switch to color scheme z

Thanks.

0 Likes

#4

Have a look in “Preferences/File Settings - Default” for a list of everything you can put in there. You want the color_scheme key:

"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme"
0 Likes

#5

Thanks. Excuse my ignorance.

I’m not sure how one would change that line of code so that it picks a color scheme depending on the type of file. I did not see any other settings in the default that would help.

Would one do something like this?

{
“.cfm”: “Packages/coldfusion.tmTheme”,
“.js”: “Packages/js.tmTheme”,
“.pl”: “Packages/perl.tmTheme”
}

Thanks again.

0 Likes

#6

When you have a “.js” file open, use the menu to open the syntax-specific settings file (Preferences / File Settings - More / Syntax Specific - User). If you look at the name of the file that has been opened, you should be able to see that this file is specific to JavaScript files (Packages/User/JavaScript.sublime-settings). Add the setting as jps suggested before and it should work as desired.

You will need to do this for each file type that you want to have special syntax highlighting.

0 Likes

#7

@sublime_user: open a cfm file (or set syntax as cfm) then go to preferences -> file settings (more) -> syntax specific and add:

{ "color_scheme": "Packages/cfm/custom-theme.tmTheme" }
Do the same for every language.

Enjoy!

0 Likes

#8

Awesome! Thanks! Got it working.

0 Likes

#9

Is it possible to have file specific syntax? - for example, if I like to see a specific file with specific font size, italics, etc.?

0 Likes

#10

You’ll need a plugin for this. But why do you need this?

0 Likes

#11

I’m running Version 3.0, Build 3143 and I’m not immediately seeing how to translate the instructions above to my version…

0 Likes

#12

The menu layout has changed a bit over the years, so the new set of instructions to do this in Sublime Text 3 would be:

  1. Open a file of the type you want a custom color scheme for
  2. Select Preferences > Settings - Syntax Specfic from the menu (Preferences is under Sublime Text if you are on MacOS)
  3. Add an appropriate Color Scheme setting to the right hand panel.

The settings now open in a split window with the default settings on the left and your settings on the right (in this case syntax settings), so you can copy the default setting for the color scheme and then modify it as needed.

If you’re unsure, you can temporarily set the global color scheme to the one you want to use and then select Preferences > Settings from the same menu to see what the value of the setting needs to be.

1 Like

#14

For me I wanted to add color scheme to .conf (apache) file

opend myFile.conf in Sublime

Tools > Command Pallet > Set Syntax : groovy

I chose “groovy” you can choose which ever one you want.

0 Likes

#15

All the answers don’t answer the question completely.

The question wants a set up. that auto switch color theme when they open a js or a markdown file. Automatically.

0 Likes

#16

This is exactly what most of these answers are about, most notably OdatNurd’s which explains every step.

If you are having problems with executing the instructions in there, we could help you much better if you laid out what part you are having problems with.

0 Likes