There are three ways to do that, view.run_command()
, window.run_command()
and sublime.run_command()
. All of them take the same arguments, first the name of the command, and second the arguments:
window.run_command("set_max_columns", {"columns": 10})
Without going into a ton of details, you generally want view.run_command()
if you’re going to run a command that modifies a specific tab (aka view
) somehow (like altering or adding text, moving the cursor, etc) and window.run_command()
for everything else.
window.run_command()
can run any command, including the commands that view.run_command()
can run, but for an command that’s view
specific it will automatically select the currently active view
and ask it to run the command, which won’t do what you expect if you do it from the console because all places where you can type text in Sublime are view
s, including the input area in the console.
For example, compare the results of the following two things and see what happens:
view.run_command('insert', {'characters': 'Hello, World!'})
window.run_command('insert', {'characters': 'Hello, World!'})