Search code examples
sublimetextsublimetext3

Sublime Text 3 - Change color of just one window?


I use multiple windows of Sublime Text at once and would like to set each one to a different color theme. By default, changing the 'color preferences' changes them for all open windows.

Note it is possible to set the color scheme for a single window using a 'project settings' file (which suggests it is possible in general), but then the folder must be opened via the 'project settings' (and not just opening the folder).

How can I (programmatically or via the app) set a separate color scheme for a single SublimeText window?


Solution

  • You can do this with a small plugin. Create a new file with Python syntax, and the following contents:

    import sublime_plugin
    
    
    class ChangeWindowColorSchemeCommand(sublime_plugin.WindowCommand):
        def change_scheme(self, scheme):
            for view in self.window.views():
                view.settings().set("color_scheme", scheme)
    
        def run(self):
            message = 'Enter path to color scheme:'
            path = 'Packages/Color Scheme - Default/Monokai.tmTheme'
            self.window.show_input_panel(message, path, self.change_scheme, None, None)
    

    Save the file in your Packages/User folder (accessible via Preferences -> Browse Packages...) as change_window_color_scheme.py. You can trigger the plugin in two ways - from the console, and via a key binding. To run it via the console, open the console with Ctrl` and enter

    window.run_command('change_window_color_scheme')
    

    An input panel will open at the bottom of the window, where you can enter the path to the color scheme you want to use. The default value is Monokai, but you can change that in the plugin source if you want. Once you enter the path, hit Enter and all the files in the current window will use that color scheme.

    To create a key binding, open Preferences -> Key Bindings-User and add the following:

    { "keys": ["ctrl+alt+shift+s"], "command": "change_window_color_scheme" }
    

    If the file is empty, surround the above with square brackets [ ]. Save the file, and you can now trigger the plugin using CtrlAltShiftS, or whichever key combination works best for you.