Sublime Forum

How do I use subl --command at a cmd prompt

#1

At the cmd prompt, type C:> subl --command select_all to get better execution.

The command command is searched using sublime Keymap.

For example
For select_all,

{“keys”: [“ctrl + a”], “command”: “select_all”}

I would like to know how to use the example below.

{“keys”: [“ctrl + backspace”], “command”: “delete_word”, “args”: {“forward”: false}}

I don’t know how to use “args” like
You probably know how to use the args parameter with cmd propt.

1 Like

#2

The value of the --command argument to subl is a single string that represents the command to execute and the arguments to pass to the command (if any are needed). The arguments you provide should be in a JSON dict just like they would appear in Sublime.

Since both the command and the arguments need to be in a single command line argument, you need to wrap the command and the arguments in quote characters so that the command prompt will see them as a single argument. However, quote characters are also needed in the JSON args to the command, so you need to quote them so that the command interpreter will leave them alone.

For the example you provided above, that would look like:

subl --command "delete_word {\"forward\": false}"
2 Likes

How to run a command with arguments from command line on Windows
#3

Thanks for this suggestion.

I would like to execute, from the command line, a RegReplace command that I have configured in ST and that I normally run through the Command Palette, because I should run this command for more than a hundred files at a time.

The following does not work (it only open the file DA-test.xml without executing the command):

subl --command “RegReplace: Replace in LN only XML export files” DA-test.xml

I would appreciate your help in pointing out my mistake.

Alternatively (if that is not possible), I am wondering if it is possible to execute once a command via the command palette, for all the files that are open in ST.

Thank you for your help

0 Likes

#4

As noted in the example above, the command that you are providing needs to be the actual command to execute, not the name of an entry in the command palette.

You would have to know what command and arguments that command palette entry is using and use that in your subl call.

0 Likes