Visual Studio Code command for "repeat last command"
If you are specifically looking to rerun the last shell command, see Make a keybinding to run previous or last shell commands
Older answer (see above)
So this is a little funky because for the workbench.action.acceptSelectedQuickOpenItem
command to work, the command palette must be open. So it will flash open briefly whenever you use the macro keybinding.
Using the macrosRe extension:
"macros": {
"rerunCommand": [
"workbench.action.showCommands",
"workbench.action.acceptSelectedQuickOpenItem"
]
}
I assume you have "workbench.commandPalette.history": 50,
set to at least one so that the most recently used command is at the top of the command palette. [I think that setting always puts the last command at the top and selects it.]
And then some keybinding:
{
"key": "ctrl+;",
"command": "macros.rerunCommand"
},
You can press Ctrl + Shift + P
, then Enter
it also repeat the lastest command.
Take a look:
On Mac simple Ctrl-P repeats the last command on the terminal. Looks like they updated it!
If you are specifically looking to rerun the last shell command, see Ctrl-R, with Make a keybinding to run previous or last shell commands
Actually, with VSCode 1.70 (July 2022), Ctrl-R is no longer limited to running the last command.
See issue 154306 "Add context key for run recent command open"
The views picker (Ctrl-q) lets you hit Ctrl-q again to go down the list:
{ "key": "ctrl+q", "command": >"workbench.action.quickOpenNavigateNextInViewPicker", "when": "inQuickOpen && inViewsPicker" },
This is behavior we could copy in the
run recent command
to make it act even more like Ctrl-R in the shell
This is implemented in PR 154552 and released in VSCode Insiders.
You now have the possibility to associate to your key shortcut a
"when": "InTerminalRunCommandPicker"
And with VSCode 1.71 (Aug. 2022):
allow recent commands to be pinned
From issue 154388: Allow pinning of commands in Run recent command quickpick
From
To:
This is released in VSCode Insiders today.