Sublime Forum

Run Multiple Commands.. Command


Hi Nilium,

Thanks a lot for the code - nice job!

I have used it to have a ( simple ) 2 Columns Layout Management - see


1 Like


Thank you for the plugin – greatly appreciated !!! This is a really easy method to chain together predefined plugins.

1 Like

Problem execute Multiple_Commands: "Split_selection_into_lines"

After several hours of experimenting, I was unable to get the lambda timeout code to work with this particular plugin. I ended up including a lambda timeout statement within the particular plugin that was being chained as a workaround. If anyone could please provide a few keymap examples of how to use the lambda timeout code proposed by sashabe, that would be greatly appreciated.

1 Like


I don’t have any example, but I’m not really sure what sashabe was trying to do. Using set_timeout will in fact cause the commands to be delayed by the specified time. But note that the method will return immediately. The subsequent commands will be issued with the the same timeout, but issued “instantaneously”, so I don’t think you would get the delay between commands you want. I could be wrong though, I didn’t test it. I was linking to this post and decided to browse through the thread while I was at it :smile:

1 Like


Yes, skuroda, that does indeed explain the behavior I was experiencing with the sashabe code modification. Thank you.

1 Like


Hi everybody, it’s the same sashabe, I was forced to register under new user name because the forum doesn’t allow you to reset passwords if forgotten.
Here’s a bit modified version of plugin which allows custom delays to be given for each executed command. If no argument is present the delay=0.
To skuroda - I experienced no problems with delay working on Windows and Mac.

import sublime, sublime_plugin

# Takes an array of commands (same as those you'd provide to a key binding) with
# an optional context (defaults to view commands) & runs each command in order.
# Valid contexts are 'text', 'window', and 'app' for running a TextCommand,
# WindowCommands, or ApplicationCommand respectively.
class RunMultipleCommandsCommand(sublime_plugin.TextCommand):
  def exec_command(self, command):
    if not 'command' in command:
      raise Exception('No command name provided.')

    args = None
    if 'args' in command:
      args = command'args']

    # default context is the view since it's easiest to get the other contexts
    # from the view
    context = self.view
    if 'context' in command:
      context_name = command'context']
      if context_name == 'window':
        context = context.window()
      elif context_name == 'app':
        context = sublime
      elif context_name == 'text':
        raise Exception('Invalid command context "'+context_name+'".')

    if 'delay' in command:
      delay = command'delay']
      delay = 0

    # skip args if not needed
    if args is None:
      sublime.set_timeout(lambda: context.run_command(command'command']),delay)
      sublime.set_timeout(lambda: context.run_command(command'command'], args),delay)

  def run(self, edit, commands = None):
    if commands is None:
      return # not an error
    for command in commands:
      # sublime.set_timeout(lambda: self.perform_action(view),2500)

Below is an example of key config:

{ "keys": "ctrl+alt+s"],
    "command": "run_multiple_commands",
    "args": {
        {"command": "next_view", "context": "window","delay":2500}, 
        {"command": "sftp_upload_file", "context": "window","delay":2500},
        {"command": "prev_view", "context": "window","delay":0}

Multiple command with custom delay for each

I just ran your plugin (replaced sftp_upload_file with save and changed the context accordingly). The save occurs after 2.5 seconds. I think lawlist wanted the commands to occur in such a way that the save would execute after 5 seconds had passed. I tested on W7 x64 build 3046.

1 Like



I tried this to execute a bash script on save (synching files to a remote server). However, only the save command is executed. Does this solution work with external scripts?

  { "keys": "f2"], 
    "command": "run_multiple_commands",
    "args": {
          "command": "save" 
          "command": "exec", 
          "args": { "cmd": "/Users/myusername/scripts/myscript"] }

Binding the script alone to a key does work and I can see it being executed in the Sublime Text console.

1 Like


So, as far as I can tell this functionality is basically fundamental to being able to define repeated commands, i.e. this is the equivalent of concatenation in a vimscript map.

Will this become the standard way of scripting keys for vintage mode or all of sublime text? It would appear that the alternative is to extract out whatever behavior it is you want and make a whole plugin for it, which is perhaps not completely absurd but a heckuva lot more work than e.g. writing a new vim bind in the vimrc!

Even defining the new JSON definition using this plugin is much harder than in most anything else… I just really wish there was a more clean way to do it.

I really appreciate the work to make this function, though. Good job. :smiley:

1 Like


Is there any way to get this working with ST3?

I’ve tried placing it in the same folder as I do in my ST2 (where it works like charm), but I’m not able to get it working…

Any help?


1 Like


Nilium: is this available as a standalone package? If not, would you be up for making one or okay if I made one?

1 Like


I’m trying to use chained commands with SublimeREPL but it’s not working, any tips?

	{"keys": "ctrl+alt+b"],
	 	"command": "run_multiple_commands",
	 	"args": {
	 			{"command": "save"},
	 			{"command": "run_existing_window_command", "args": {
		 				"id": "repl_python_run",
		    			"file": "config/Python/Main.sublime-menu"	

I tried the Chain of Command package, but doesn’t work too.

1 Like


Tried changing the context?

1 Like


I tried. The first command works, the save, but the next command is not executed…

I’m using ST3, I don’t know if can be a compatibility issue.

1 Like


Can you please be more specific?

I’m sorry, this is a big thread. I though it was a orphan question.

1 Like


With “context”: “window”, in both commands, it works, sorry. You should make a package of it, the Chain of Command package doesn’t work like this.


1 Like


@jjforums, I had made some fixes to this plugin and it is available at I had originally intended to find some way to replace the built in macro functionality, but never figured out a good way to record all commands. Anyways, run_multiple_commands command (and a file variant) are bundled in the previously mentioned package. Not part of package control, since it’s incomplete to me, but you can add it as a repository, and it will auto update as if it were in package control.

1 Like


This is a very useful tool and I appreciate the efforts…so a big thank you!
Quick question on this…I have it working for what I need thus far…with one minor issue - after running through my third command string (which is referencing the “Goto” overlay I have a manual entry to make so I set a delay; however i can’t get the commands to pick back up and execute. I’m assuming it’s because I’ve flipped into the “Goto” overlay and that’s the termination factor here.
Below is my code and what I’m trying to get it to do per the “Multiple Commands” Pluggin:
{ “keys”: “ctrl+shift+m”], “command”: “run_multiple_commands”,
“args”: {
{“command”: “instant_file_search”, “context”: “window”, “delay”: 0},
{“command”: “type_criteria”, “context”: “window”, “delay”: 0},
{“command”: “show_overlay”, “args”: {“overlay”: “goto”, “text”: “:”}, “context”: “window”, “delay”: 3500},
{“command”: “move_to”, “args”: {“to”: “eol”, “extend”: true}, “context”: “window” },
{“command”: “move”, “args”: {“by”: “pages”, “forward”: true, “extend”: true},“context”: “window” },

Any help/suggestions on this would be wonderful! :smiley:

1 Like


@woodring, Are you expecting type_criteria to run, then wait 3.5 seconds for entry? If the goto panel is where you are expecting to do the manual entry, try moving the delay to the next command. I tried a simplified version, using the 4th and 5th commands and the delay on the second. It seemed to work okay.

1 Like


Very useful code!

Fine for quickly executing more than one command by a keyboard short-cut without the need to write a script for that.

Thank you, Nilium!

1 Like