Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 463
sellarafaeli Avatar asked Oct 10 '14 20:10

sellarafaeli


People also ask

How do I change the Color Scheme in Sublime Text 3?

Sublime Text 3 has a number of pre-installed themes that can be enabled by clicking on “Preferences” in the top bar, then clicking “Color Scheme”. Click on “Preferences” in the top bar, then click “Color Scheme”. Next, a box will appear at the top of the window, with a few options.

How do I change the selection color in Sublime Text?

Changing the selection colour in Sublime Text 3 Open the command palette with ⌘+⇧+P on mac iOS (for windows/linux Ctrl + Shif + P) and type prv to get the PackageResourceViewer options. Choose Open Resource >> Color Scheme – Default >> and choose your theme file to edit.


1 Answers

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.

like image 82
MattDMo Avatar answered Nov 15 '22 07:11

MattDMo