Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keyboard shortcut to change color scheme in Sublime Text 2?

is there a way to assign a keyboard shortcut to a specific color scheme in Sublime Text 2? In Emacs it's easy to define a function that toggles "night-mode" color scheme and assigns it to a keyboard shortcut, I was wondering if you can also do it in ST2.

Piotr

like image 663
pkazmierczak Avatar asked Oct 29 '12 12:10

pkazmierczak


2 Answers

Try something like this, in your user key binding:

{
    "keys": ["YOUR_SHORTCUT"],
    "command": "set_setting",
    "args":
    {
        "setting": "color_scheme",
        "value": "Packages/Color Scheme - Default/Solarized (Light).tmTheme"
    }
}

Of course, change Packages/Color Scheme - Default/Solarized (Light).tmTheme to whatever theme you prefer.

If you want a toggle between two color schemes, you can create a plugin (Tools/New Plugin...):

import sublime, sublime_plugin

class ToggleColorSchemeCommand(sublime_plugin.TextCommand):
    def run(self, edit, **args):

        scheme1 = args["color_scheme_1"]
        scheme2 = args["color_scheme_2"]
        current_scheme = self.view.settings().get("color_scheme")

        new_scheme = scheme1 if current_scheme == scheme2 else scheme2
        self.view.settings().set("color_scheme", new_scheme)

and save it in your Packages/User directory.

Then add a key binding like this:

{  
    "keys": ["YOUR_TOGGLE_SHORCUT"], "command": "toggle_color_scheme",
    "args":
    {
        "color_scheme_1": "Packages/Color Scheme - Default/Solarized (Light).tmTheme" ,
        "color_scheme_2": "Packages/Color Scheme - Default/Solarized (Dark).tmTheme"
    }
}
like image 160
Riccardo Marotti Avatar answered Dec 09 '22 07:12

Riccardo Marotti


If you don't want to bother with editing config files you can install SchemeCycle.

Then cycle color schemes with F8 and Shift+F8. With 2 themes (Dark / Light) it acts as toggling.


If you prefer Command Palette check Norris's answer or try ColorSchemeSelector with : Select Color Scheme command, it will not pollute your pallete as much as Schemr.

Visualization AKA screens:

enter image description hereenter image description here

like image 27
A.D. Avatar answered Dec 09 '22 09:12

A.D.