Reputation: 853
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
Upvotes: 26
Views: 12266
Reputation: 618
There is a way to change a color scheme along with a theme with Camaleon plugin.
Upvotes: 4
Reputation: 593
If someone interested I just created a plugin to toggle between N different theme and colorscheme configurations. Check it out here:
https://gist.github.com/andresbravog/9429793
Upvotes: 3
Reputation: 101
To change global color scheme settings (not just the current view), alter Riccardo's answer like this:
import sublime, sublime_plugin
class ToggleColorSchemeCommand(sublime_plugin.TextCommand):
def run(self, edit, **args):
s = sublime.load_settings("Preferences.sublime-settings")
scheme1 = args["color_scheme_1"]
scheme2 = args["color_scheme_2"]
current_scheme = s.get("color_scheme", scheme1)
new_scheme = scheme1
if current_scheme == scheme1:
new_scheme = scheme2
if current_scheme == scheme2:
new_scheme = scheme1
s.set("color_scheme", new_scheme)
sublime.save_settings("Preferences.sublime-settings")
Make sure all of your views are set to one color scheme before using this!
This should work no matter what your color schemes are currently set to under "Preferences.sublime-settings - User" and "Preferences.sublime-settings - Default".
I gleaned this information from Schemrs code: https://github.com/benweier/Schemr/blob/master/schemr.py and the font-changing code: "Packages\Default\font.py"
Upvotes: 10
Reputation: 4614
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:
Upvotes: 13
Reputation: 2259
To support multiple color schemes one would alter Riccardos answer like so:
class ToggleColorSchemeCommand(sublime_plugin.TextCommand):
def run(self, edit, **args):
scheme1 = args["color_scheme_1"]
scheme2 = args["color_scheme_2"]
scheme3 = args["color_scheme_3"]
current_scheme = self.view.settings().get("color_scheme")
new_scheme = scheme1
if current_scheme == scheme1:
new_scheme = scheme2
if current_scheme == scheme2:
new_scheme = scheme3
self.view.settings().set("color_scheme", new_scheme)
Upvotes: 5
Reputation: 3545
I just found this nice little plugin: https://github.com/skt84/Schemr
Which doesn't exactly allow you to bind, but gives you a Command Palette access instead, which does just perfect for me. (Just in case anyone stumbled on this via google like myself.)
Upvotes: 7
Reputation: 20348
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"
}
}
Upvotes: 49