Eternity Neet
Eternity Neet

Reputation: 179

sublime key binding to set multiple settings from one key binding

I'm using Sublime Text 3.

I can change font-face using key bindings with this code:

[
    {
        "keys": ["ctrl+0"], "command": "global_set_setting",
        "args": {
            "setting": "font_face",
            "value": ""
        }
    },
    {
        "keys": ["ctrl+1"], "command": "global_set_setting",
        "args": {
            "setting": "font_face",
            "value": "Courier New"
        }
    },
]

But, I want to change color scheme too at the same time.

What I've tried:

[
    {
        "keys": ["ctrl+0"], "command": "global_set_setting",
        "args": {
            "setting": "font_size",
            "value": 10,
            "setting": "font_face",
            "value": "",
            "setting": "color_scheme",
            "value": "Monokai.sublime-color-scheme"
        }
    },
    {
        "keys": ["ctrl+1"], "command": "global_set_setting",
        "args": {
            "setting": "font_size",
            "value": 10,
            "setting": "font_face",
            "value": "Courier New",
            "setting": "color_scheme",
            "value": "Celeste.sublime-color-scheme"
        }
    },
]

Current Result: The only change that will be applied is the last parameter which is color scheme only

Expected Result: I want to change all the setting in the parameter at the same time (using one hotkey)

Is it possible to do that with key bindings? if yes, how do I make key bindings to do that?

Upvotes: 1

Views: 456

Answers (1)

mattst
mattst

Reputation: 13950

There is a Sublime Text plugin called Preset Command that does exactly what you want. It is available on Package Control: Preset Command

It works by the user defining the groups of settings that they want in a Presets.sublime-settings file, these groups must be given a name. A key binding or palette command can then be added in the usual way to call the plugin using the name assigned to a group of settings. The plugin has detailed and well written instructions.

For example the settings setup you used in your question would require the following steps:

1) Install Preset Command using Package Control.

2) Place the following lines in the file: Path_To/sublime-text-3/Packages/User/Presets.sublime-settings

You can create or open it easily with: Menu --> Preferences --> Package Settings --> Preset Command --> Manage Presets

{
    "presets":
    [
        {
            "name": "MonokaiSettingsPreset",
            "description": "Monokai, No Font Set, Size 10",
            "settings": {
                "Preferences.sublime-settings": {
                    "font_size": 10,
                    "font_face": "",
                    "color_scheme": "Monokai.sublime-color-scheme"
                }
            }
        },
        {
            "name": "CelesteSettingsPreset",
            "description": "Celeste, Courier New, Size 10",
            "settings": {
                "Preferences.sublime-settings": {
                    "font_size": 10,
                    "font_face": "Courier New",
                    "color_scheme": "Celeste.sublime-color-scheme"
                }
            }
        }
    ]
}

3) Place the following lines, with whatever keys you want to use, in your keys file: Path_To/sublime-text-3/Packages/User/Default (Your OS).sublime-keymap

{ "keys": ["ctrl+k", "1"],
  "command": "preset_command_by_name",
  "args": { "name": "MonokaiSettingsPreset" } },

{ "keys": ["ctrl+k", "2"],
  "command": "preset_command_by_name",
  "args": { "name": "CelesteSettingsPreset" } },

Upvotes: 2

Related Questions