Search code examples
sublimetext3key-bindings

How to switch to command mode after press "Save" hotkey in Sublime Text 3?


SUBJ. I recently switched to Sublime from vim and trying to configure Sublime Text 3 in the way which I used to.

If I add binding, like below:

{ "keys": ["super+s"], "command": "exit_insert_mode", "context":
    [
      { "key": "setting.command_mode", "operand": false },
      { "key": "setting.is_widget", "operand": false }
    ]
}

it switches mode to command, but do not save changes.


Solution

  • What you have specified overrides the existing save key binding, so it is behaving as expected. You will need to use a plugin or a macro to get the behavior you want. A macro would require you to save an additional file, so that's up to you. For a plugin solution, you should be able to use https://github.com/skuroda/ImprovedMacros to get the behavior you want. Replaying commands is based on some work I found on the ST forums. Never got around to finding a good way to record actions better though. That aside, there are install instructions in the README. I believe the following will work as your key binding with the plugin installed

    {
        "keys": ["super+s"], "command": "run_multiple_commands",
        "args": {
            "commands": [{
                "context": "view",
                "command": "save"
            },{
                "context": "view",
                "command": "exit_insert_mode"
            }]
        },
        "context": [
            { "key": "setting.command_mode", "operand": false },
            { "key": "setting.is_widget", "operand": false }
        ]
    }