Sublime Forum

Modifying Color Scheme and Theme globally with a Keyboard Shortcut

#1

Hey everyone!

I would like to be able to quickly switch back and forth between a light theme and a dark theme by pressing a keyboard shortcut.

I tried using the Multicommand plugin, in combination with the set_setting command, to create two key bindings that I can use for that purpose.

However, I noticed it only affects the current window. After reading the Themes documentation, I noticed that:

The settings modified here are buffer specific settings: they override any settings placed in a settings file, but apply to the current file only.

Is there a way to persist the modified settings globally instead of modifying the local buffer settings?

For reference, these are the key bindings I’m using:

  {
    "keys": ["super+ctrl+l"],
    "command": "multicommand",
    "args": {
      "commands": [
        {
          "command": "set_setting",
          "args":
          {
            "setting": "color_scheme",
            "value": "Packages/User/Color Highlighter/themes/Solarized Flat Light.tmTheme"
          }
        },
        {
          "command": "set_setting",
          "args":
          {
            "setting": "theme",
            "value": "Solarized Flat Light.sublime-theme"
          }
        },
      ]
    }
  },
  {
    "keys": ["super+ctrl+o"],
    "command": "multicommand",
    "args": {
      "commands": [
        {
          "command": "set_setting",
          "args":
          {
            "setting": "color_scheme",
            "value": "Packages/Material Theme - Mod/Material-Theme-Darker.tmTheme"
          }
        },
        {
          "command": "set_setting",
          "args":
          {
            "setting": "theme",
            "value": "Material-Theme-Darker.sublime-theme"
          }
        }
      ]
    }
  }

Thanks!

1 Like

Toggle comment color
#2

Ended up creating a custom plugin for this purpose, which allows me to toggle by using the toggle_color_scheme command.

Sharing the code here in case it’s helpful, it will require customizing the selected themes and color schemes, which could be received as arguments if preferred:

import sublime
import sublime_plugin


class ToggleColorSchemeCommand(sublime_plugin.TextCommand):
  def run(self, edit, **args):
    settings = sublime.load_settings("Preferences.sublime-settings")

    light_theme = "Solarized Flat Light.sublime-theme"
    dark_theme = "Material-Theme-Darker.sublime-theme"

    dark_color_scheme = "Packages/Material Theme - Mod/Material-Theme-Darker.tmTheme"
    light_color_scheme = "Packages/User/Color Highlighter/themes/Solarized Flat Light.tmTheme"

    current_theme = settings.get("theme", light_theme)

    if current_theme == light_theme:
      settings.set("theme", dark_theme)
      settings.set("color_scheme", dark_color_scheme)
    else:
      settings.set("theme", light_theme)
      settings.set("color_scheme", light_color_scheme)

    sublime.save_settings("Preferences.sublime-settings")
2 Likes

#3

Hi, welcome to the sublime forum!

I use a package called QuickThemes.
Check this link: https://packagecontrol.io/packages/QuickThemes

Or you can use another one called Skins:
https://packagecontrol.io/packages/Skins

1 Like