Here is my problem: when writing javascript for both server and client-side, I regularly share methods and/or have close file names. I would love to be able to keep the context in mind, just by the background color of the opened files. I thus look for a way to tell sublime text to use one color scheme for files in the server folder and an other for those in the client folder: any clue on how I could do that?
I'm not sure it's even possible as it would imply a per-folder config file I guess, but that's my bottle in the sea... thanks!
The easiest way to do this is with projects. Set up a project for your client-side folder, and another for your server-side folder. Then, go to Project -> Edit Project
and you'll see something like this:
{
"folders":
[
{
"follow_symlinks": true,
"path": "/home/mattdmo/Projects/js/MySweetApp/server-side"
}
]
}
There are two other top-level arrays you can add: "settings"
and "build_systems"
. The settings
section can include anything that goes in Preferences -> Settings-User
, including "color_scheme"
:
{
"folders":
[
{
"follow_symlinks": true,
"path": "/home/mattdmo/Projects/js/MySweetApp/server-side"
}
],
"settings":
{
"color_scheme": "Packages/Neon Color Scheme/Neon.tmTheme"
}
}
Just edit both .sublime-project
files you made earlier to add a settings
section and different color_scheme
choices within, and you'll be all set.
While pondering this again, I came up with a different solution using a plugin. Create a new Python file with the following contents:
import sublime
import sublime_plugin
class ClientServerColorSchemeCommand(sublime_plugin.TextCommand):
def run(self, edit):
if "/server/" in self.view.file_name():
self.view.settings().set("color_scheme",
"Packages/User/server.tmTheme")
elif "/client/" in self.view.file_name():
self.view.settings().set("color_scheme",
"Packages/User/client.tmTheme")
class ClientServerEventListener(sublime_plugin.EventListener):
def on_load_async(self, view):
view.run_command("client_server_color_scheme")
Make sure you adjust the "color_scheme"
settings to the color schemes you want to use for client and server files, and feel free to tweak "/server/"
and/or "/client/"
in the if/elif
statements if you want to make them more specific. If you're on Windows, change the forward slashes /
to double back-slashes \\
. Save the file as Packages/User/client_server_color_scheme.py
where Packages
is the folder opened when selecting the Preferences -> Browse Packages...
menu option.
Once saved, the event listener will start up immediately, and any file you open that contains the specified path will have the color scheme set to whatever you indicate. All other files from other paths will use your default color scheme.
Please note that this plugin will only work in ST3. To make it work in ST2, change def on_load_async
to def on_load
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With