Skip to content

Instantly share code, notes, and snippets.

@rbf
Forked from jasonlong/Default (OSX).sublime-keymap
Last active March 4, 2024 19:14
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rbf/195acdfe8f51b65e5ecd to your computer and use it in GitHub Desktop.
Save rbf/195acdfe8f51b65e5ecd to your computer and use it in GitHub Desktop.
A simple way to toggle between dark and light themes in Sublime Text 2 and 3.
// Copy this to your keybindings (Preferences > Key Bindings - User)
// Change the keybinding, color schemes, and themes to your preferences
{
"keys": ["ctrl+shift+s"], "command": "toggle_color_scheme",
"args": {
"light_color_scheme": "Packages/Solarized Color Scheme/Solarized (light).sublime-color-scheme",
"dark_color_scheme": "Packages/Solarized Color Scheme/Solarized (dark).sublime-color-scheme",
"light_theme": "Adaptive.sublime-theme",
"dark_theme": "Adaptive.sublime-theme"
}
}
# From https://gist.github.com/rbf/195acdfe8f51b65e5ecd
# Forked from https://gist.github.com/jasonlong/5395357
# Install with:
# curl -#SL https://gist.github.com/rbf/195acdfe8f51b65e5ecd/raw/ToggleColorSchemeCommand.py -o ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/User/ToggleColorSchemeCommand.py
# // Copy this to your keybindings (Preferences > Key Bindings - User)
# // Change the keybinding, color schemes, and themes to your preferences
#
# {
# "keys": ["ctrl+shift+s"], "command": "toggle_color_scheme",
# "args": {
# "light_color_scheme": "Packages/Solarized Color Scheme/Solarized (light).sublime-color-scheme",
# "dark_color_scheme": "Packages/Solarized Color Scheme/Solarized (dark).sublime-color-scheme",
# "light_theme": "Adaptive.sublime-theme",
# "dark_theme": "Adaptive.sublime-theme"
# }
# }
import sublime, sublime_plugin
class ToggleColorSchemeCommand(sublime_plugin.TextCommand):
def run(self, edit, **args):
light_color_scheme = args["light_color_scheme"]
dark_color_scheme = args["dark_color_scheme"]
light_theme = args["light_theme"]
dark_theme = args["dark_theme"]
settings = sublime.load_settings('Preferences.sublime-settings')
current_color_scheme = settings.get('color_scheme')
if current_color_scheme == light_color_scheme:
settings.set('color_scheme', dark_color_scheme)
settings.set('theme', dark_theme)
else:
settings.set('color_scheme', light_color_scheme)
settings.set('theme', light_theme)
sublime.save_settings('Preferences.sublime-settings')
@cnicolai
Copy link

That is very helpful, thank you!

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