When creating keyboard shortcuts, it would be nice if you could pass an array of commands (to execute like a macro) that would run the commands in that order.
So take this for example:
{
"key": "ctrl+s",
"command": [
"editor.action.format",
"editor.action.trimTrailingWhitespace",
"workbench.action.files.save"
],
"when": "editorTextFocus"
}
It would format the file, remove trailing white space then save the file.
Abolutely what I was thinking! - another example (mine)
{
"key": "winl+b",
"command": [
"workbench.action.tasks.terminate",
"workbench.action.tasks.build"
]
}
love this idea
Show any plain text in addition to commands will be great:
For example, using ctrl+;
to move to the end of line and add ;
and then move to the next line.
{
"key": "ctrl+;",
"commands": [
"cursorEnd",
";",
"editor.action.insertLineAfter"
],
"when": "editorTextFocus"
}
I'm surprised to see so few votes on this issue. I was looking for a way to bring up a terminal and hide the file explorer at the same time, since the integrated terminal doesn't occupy 100% width, and it seems vscode does'nt support multiple commands on a single keybindings yet. :(
Also, #6617 for ref.
+1
+1
+1
Hi guys, I've just found out the extension macros which is exactly I was looking for. Hope this helps you overcome this limitation.
You probably want to allow arguments, for example when using the type
command:
{
"key": "ctrl+;",
"commands": [
{
"command": "cursorEnd"
},
{
"command": "type",
"args": { "text": ";" }
}
]
"when": "editorTextFocus"
}
If anyone on the core team would flag this with "help wanted" or "good first issue" i'd love to help out !
Ok so this isn't really answer to issue in vscode, but one work around i found was to use autohotkey.
FYI, I know this is slightly off-topic but for anyone using their machine to code and as a gaming platform: autohotkey can trigger video games anti-cheat programs. If you don't want to get kicked/banned during your next session of battlefield, be sure to have autohotkey turned off before playing. :)
Bump. This would be very very helpful.
I'd also love to have this feature :)
Is this workable now? I want to customize vscode suggestion selection just like Visual Studio "select" and "print . or ("
When could we have this feature :(
Use case: comment/uncomment line and move cursor down like in IntelliJ IDEA.
{
"key": "cmd+/",
"command": ["editor.action.commentLine", "cursorDown"],
"when": "editorTextFocus && !editorReadonly"
}
Another use case is to locate the file in file explorer and make the file explorer active like resharper.
{
"key": "shift+alt+l",
"command": ["workbench.files.action.showActiveFileInExplorer", "workbench.view.explorer"]
}
You can currently do this using the multi-command vscode extension! 馃槂
+1, surprised that this generic feature does not exist in the base vscode
Please add this feature, very much needed!
Until we'll have it in vscode, thanks @jessedvrs, with this extension I was able to create a keybinding for a common operation
1) save all files
2) git refresh (another open vscode issue is that you have to click 'refresh' manually sometimes)
3) commit all files (it opens a popup to enter the commit message)
userSettings:
"multiCommand.commands": [
{
"command": "multiCommand.quickGitCommit",
"sequence": [
"workbench.action.files.saveAll",
"git.refresh",
"git.commitAll",
]
}
]
keybindings.json
{
"key": "F4",
"command": "multiCommand.quickGitCommit",
"when": "editorTextFocus"
}
Maybe someone can explain to me, what i'm doing wrong, cos this doesn't seem to work for me:
@PragmaticEd why is multiCommand.commands
underlined in green? Have you installed the right extension, https://marketplace.visualstudio.com/items?itemName=ryuta46.multi-command? (Maybe this is not the right place to discuss this - what would be a better one?)
@bersbersbers I found another, even nicer-looking, solution in plugin called macros
After installing plugin:
In user settings:
{
"macros": {
"commentAndMoveDown": [
"editor.action.commentLine",
"cursorDown",
"cursorLineStart"
]
}
}
in keybindings.json
[
{
"key": "ctrl+shift+c",
"command": "macros.commentAndMoveDown"
}
]
how is this not a feature yet?
@mackcoding I feel like it should be..
Not a feature yet?
In the mean time, one can use macros.
much needed feature, should be native.
needed here ! :)
Still looking for this feature.
Would love this feature as well. Would also like to see it in Azure Data Studio (where the 'macros' extension is NOT available), which clearly shares a common ancestry with VSCode :-)
I like it and like goto next end function maybe can achive like this:
{
"key": "shift+enter",
"command": ["cursorDown", "cursorEnd"],
"when": "editorTextFocus"
}
+1 pls :)
2019 is asking why this feature is still not added yet! @sandy081, @joaomoreno and others working on the keybindings, this Issue was opened in 2015, that's four full years of development time not spent adding an extremely useful and seemingly simple feature. The back end of the keybindings API could just concatenate the listed commands and run them one after another. Please add this, there is no official fix besides using extensions for a very basic feature!
Please add this! I really need this feature.
Please add this!
Another use case:
Hide both sidebar and activity bar at the same time:
{
"key": "ctrl+s",
"command": ["workbench.action.toggleSidebarVisibility", "workbench.activity.toggleActivityBarVisibility"]
}
Would love to see this get added as well. This allows for ultimate editor flexibility. We already have "when" context on keybindings why not multiple commands!
I know it is not what we guys want, but this is the work-around I'm using right now.
tasks-api
can take commands
#11396 and we can combine multiple tasks using dependsOn
.
So...
In tasks.json
"tasks": [
{
"label": "save_file",
"command": "${workbench.action.files.save}"
},
{
"label": "command2",
"command": "${command2}"
},
{
"label": "save_and_command2",
"dependsOn": [
"save_file",
"command2"
]
}
To set a keybinding to this task
In keybindings.json
{
"key": "ctrl+shift+f10",
"command": "workbench.action.tasks.runTask",
"args": "save_and_command2"
}
Is there any work being done for this or has it not been put on the TODO list because there are extensions for it?
@njkevlani What do you think it's the main benefit of using tasks.json
for this over e.g. macros? I guess one could argue that tasks.json
is at least natively supported by VSCode? Anything else you could think of? [Thanks for the tip by the way!]
@amelio-vazquez-reina
Initially, I was configuring _something_ to save and run a file. I configured a task for that. Later on, I wanted to get a keybinding for that and then I came across this issue and #11396 in the same time interval (I don't remember how) and felt this might be a work around for this as well.
I guess one could argue that
tasks.json
is at least natively supported by VSCode?
That's one more positive :)
+1
Bind one key to multiple commands via user level tasks, no extensions required. Not a perfect way, but it works.
I would love to have this feature too!!
Would love to see this in production :)
And array for key
:
{
"key": [
"ctrl+s",
"ctrl+alt+l"
],
"command": [
"editor.action.format",
"editor.action.trimTrailingWhitespace",
"workbench.action.files.save"
],
"when": "editorTextFocus"
}
Anything like this yet? Would love it!
I'd love to see this feature is VS Code.
I'd love this to be supported natively
I see this issue has been reported way back in 2015 and so many people have voiced to have this feature and its 2020! Still I don't see this feature has been included in VSCode! Surprising to see such a support from Microsoft. Not even a response from the core team.
It's a TOP 5 most upvoted feature request: https://github.com/microsoft/vscode/issues?q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc. 馃槩
Most helpful comment
2019 is asking why this feature is still not added yet! @sandy081, @joaomoreno and others working on the keybindings, this Issue was opened in 2015, that's four full years of development time not spent adding an extremely useful and seemingly simple feature. The back end of the keybindings API could just concatenate the listed commands and run them one after another. Please add this, there is no official fix besides using extensions for a very basic feature!