multi-command README
This extension can create command sequence as one command and bind a key, or call it manually.
Features
- create command sequence as one command and bind a key.
- call command sequence manually.
- set interval between each command execution.
Extension Settings
There is simple usage that uses only keybindings.json and a usage that uses settings.json.
Simple Usage with keybindings.json
In keybindings.json, bind a key to extension.multiCommand.execute
with passing a command sequence you want to execute as the argument.
For example:
{
"key": "alt+x",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"cursorDown",
"cursorDown",
"cursorDown"
]
}
}
This command sequence executes "cursorDown" command 3 times.
Usage with settings.json.
This usage is useful for resusing the defined command sequence in another command sequnce or executing the sequence manually.
In case using settings.json, the settings has 2 steps.
-
Create command sequence as one command in settings.json.
For example:"multiCommand.commands": [ { "command": "multiCommand.down3Lines", "sequence": [ "cursorDown", "cursorDown", "cursorDown" ] }, { "command": "multiCommand.swapChar", "interval": 30, "sequence": [ "cursorLeftSelect", "editor.action.clipboardCutAction", "cursorRight", "editor.action.clipboardPasteAction" ] } ]
First sequence is named "multiCommand.down3Lines" and executes "cursorDown" command 3 times.
Second sequence is named "multiCommand.swapChar". This sequence swaps cursor's left character and the right character. If a command is executed asynchronousely, you can set time interval between each command execution using "interval" configuration(milliseconds).
You can also use an object style that uses the command name as a key instead of an array.
"multiCommand.commands": { "multiCommand.down3Lines": { "sequence": [ "cursorDown", "cursorDown", "cursorDown" ] } }
This style is useful when you want to merge user settings and the workspace settings.
-
Bind a key to created command sequence in keybindings.json.
For example:{ "key": "F1", "command": "extension.multiCommand.execute", "args": { "command": "multiCommand.down3Lines" }, "when": "editorTextFocus" }, { "key": "F21", "command": "extension.multiCommand.execute", "args": { "command": "multiCommand.swapChar" }, "when": "editorTextFocus" }
You can bind a key to the command directly.
For example:
{ "key": "F1", "command": "multiCommand.down3Lines", "when": "editorTextFocus" }, { "key": "F2", "command": "multiCommand.swapChar", "when": "editorTextFocus" }
But when you use this key bind style, Visual Studio Code may warn about the command name. see: ryuta46#16
Manual Execution
You can call a defined command sequence from command palette.
- Open command palette ( cmd + shift + p in mac).
- Choose "Multi command: Execute multi command."
- Choose one of command sequences you defined.
If you want to call a command sequence in shorter steps, bind a key to "extension.multiCommand.execute".
For example:
{
"key": "cmd+shift+m",
"command": "extension.multiCommand.execute"
}
If you set label
and description
parameters in settings.json, they are displayed when you choose a command sequence.
Both parameters are optional.
For example:
"multiCommand.commands": [
{
"command": "multiCommand.down3Lines",
"label": "down3Lines",
"description": "down the cursor in 3 times",
"sequence": [
"cursorDown",
"cursorDown",
"cursorDown"
]
},
Advanced Settings
Pass arguments to commands
You can pass arguments to commands by defining a command sequence with args
parameter.
For Example:
{
"command": "multiCommand.cutAndType",
"sequence": [
"editor.action.clipboardCutAction",
{ "command": "type", "args": { "text": "CUT !!" } }
]
}
This sequence cut selected text and type "CUT !!".
Find the name of the command you want to execute
-
Execute "Developer: Set Log Level..." and select "trace" in the command palette.
-
Execute command of you want to know the name.
-
You can see the name in output panel for Log(Window) process( you can set the process for output in the rightside of the output panel).
Using shell commands in a command sequence
You can use shell commands in a command sequence by using Command Runner extension together.
With Command Runner extension, you can write a command sequence with shell commands as:
{
"command": "multiCommand.checkoutDevelop",
"sequence": [
{
"command": "command-runner.run",
"args": { "command": "git checkout develop" }
},
"git.sync"
]
}
See the Command Runner document for details on how to use the extension.
Release Notes
1.5.1
Support extensionKind ui or workspace.
1.5.0
New Feature: Simple usage only with keybindings.json
New Feature: Object style settings for merging user settings and workspace settings.
1.4.0
Added new style for binding a key to created commands.
1.3.0
New Feature: Manual execution from command palette.
1.2.0
New Feature: Pass arguments to commands.
1.1.0
Reloads settings.json when the file is changed.
Now, you can use a custom multi-command immediately after adding it in the settings.json without restarting vscode.
1.0.0
Initial release.