Skip to content

Instantly share code, notes, and snippets.

@jasonlong
Created April 16, 2013 11:53
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jasonlong/5395357 to your computer and use it in GitHub Desktop.
Save jasonlong/5395357 to your computer and use it in GitHub Desktop.
A simple way to toggle between dark and light themes in Sublime Text 2.
// Copy this to your keybindings (Preferences > Key Bindings - User)
// Change the keybinding, color schemes, and themes to your preferences
{ "keys": ["ctrl+1"], "command": "toggle_color_scheme",
"args": {
"light_color_scheme": "Packages/User/Espresso Soda.tmTheme",
"dark_color_scheme": "Packages/User/Monokai Soda.tmTheme",
"light_theme": "Soda Light.sublime-theme",
"dark_theme": "Soda Dark.sublime-theme"
}
}
# Copy this file to ~/Library/Application Support/Sublime Text 2/Packages/User/
import sublime, sublime_plugin
class ToggleColorSchemeCommand(sublime_plugin.TextCommand):
def run(self, edit, **args):
light_scheme = args["light_color_scheme"]
dark_scheme = args["dark_color_scheme"]
light_theme = args["light_theme"]
dark_theme = args["dark_theme"]
settings = sublime.load_settings('Preferences.sublime-settings')
current_scheme = settings.get('color_scheme')
if current_scheme == light_scheme:
settings.set('color_scheme', dark_scheme)
settings.set('theme', dark_theme)
else:
settings.set('color_scheme', light_scheme)
settings.set('theme', light_theme)
sublime.save_settings('Preferences.sublime-settings')
@jtbrough
Copy link

Thanks!

@rbf
Copy link

rbf commented May 12, 2015

A very handy small plugin indeed. Thanks!

FYI when using it in a SublimeText 2 project, only the files open after opening the project will be updated with the corresponding color_scheme. I.e. this plugin doesn't update the color_scheme for the files that were already open the last time the project was closed. That's because color_schemes are saved per view in the .sublime-workspace file when closing the project and this buffer specific settings have the highest weight in the settings hierarchy. See my fork for a quickfix.

Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment