lonix
lonix

Reputation: 21081

Visual Studio Code command for "repeat last command"

Is there a command which does "repeat last command"? If not, how can I set up such a thing?

Basically what I want is to press some shortcut, and for it to repeat whatever the last command was, so I don't have to find it again in the menu or the ctrl-shift-p box.

Upvotes: 30

Views: 22663

Answers (6)

Mwiza
Mwiza

Reputation: 9011

Click your VsCode terminal to activate it, then use the shortcut:

Ctlr + Alt + R

The most recent command is select by default, press enter.

enter image description here

Upvotes: 0

VonC
VonC

Reputation: 1328712

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

https://user-images.githubusercontent.com/35271042/178366598-9a6e520b-1e7c-4e74-ad7b-a08d4907493d.png

To:

https://user-images.githubusercontent.com/35271042/178366684-1f77ce44-ef8f-433d-b986-d3fe9b6065eb.png

This is released in VSCode Insiders today.


VSCode 1.75 (Jan. 2023) implements "Commonly Used" list in the first-time-opened Command Palette (issue 169091), with PR 171293

It adds the setting:

workbench.commandPalette.experimental.suggestCommands

Controls whether the command palette should have a list of commonly used commands.

Upvotes: 1

You can press Shift + Alt + Down arrow key it will repeat the latest command on windows VS code.

Upvotes: -5

Nadav Dafni
Nadav Dafni

Reputation: 11

On Mac simple Ctrl-P repeats the last command on the terminal. Looks like they updated it!

Upvotes: 1

Mark
Mark

Reputation: 182661

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"
}, 

Upvotes: 8

Chau Giang
Chau Giang

Reputation: 1554

You can press Ctrl + Shift + P, then Enter it also repeat the lastest command.

Take a look:

enter image description here

Upvotes: 21

Related Questions