There does not appear to be a way to re-run the previously executed task. You can either run "the build" using ctrl+shift+b, or you must explicitly select a task to run. In Atom and Eclipse, you can hit F9 to re-run your last build. This is very handy, and easily what I want to do 80%-90% of the time, just re-run my last build/task command. However, vscode does not appear to allow you to map any hot-key to the last build/task command. So if I want to run task foo, I would, effectively, have to type task foo into the command pallet every time. Things would go a lot faster if I could just type task foo into the command pallet just once, then hit a hot-key to repeat the last task.
Good suggestion. What you can do right now is to bind a keyboard shortcut to the task foo if you want to start the same task over and over again. Here is an example on how to do this:
{
"key": "ctrl+h",
"command": "workbench.action.tasks.runTask",
"args": "foo"
}
Thanks for the suggestion @dbaeumer -- Though it doesn't seem to solve the problem I'm looking for. The task I want to re-run is dependent upon both the file and lineNumber. While I'm working in other files I want to keep re-running the previous task and include those previous values and not my current values.
Common problem here is red-green testing where I run a failing test first and then modify the main body of code to fix the test. In the current flow I have to keep switching back to the test to run it which is a lot more time intensive than other platforms I've used for the same purpose (sublime and atom both have plugins for it.)
@nathanpalmer this should have improved as well by VS Code now sorting the task list in a LRU fashion. So running the last task is no Run Task (which you can bind to a keyboard shortcut) and then pressing enter.
Just tried that, had to arrow down once to hit the last task. However the problem still remains that it takes the parameters of the current file and line I'm on and not for the previous run. So unfortunately it doesn't work as needed.
Just to clarify. You want to run the task in the same state so with the variables as resolved when last run. Is this correct.
@dbaeumer i would say 'yes' to that statement. This is my explanation and workaround of the usecase i am (and it seems that @nathanpalmer too) after...
https://github.com/hendrics/python-vscode-pytest-example#running-only-subset-of-tests
@dbaeumer Yes, running the last task using the same state including variables. In my use-case it's a unit test as I'm working in other parts of the code I want to quickly re-run that same exact test.
Thanks for the suggestion @hendrics. Not exactly a perfect solution as this will run a set of tests instead of a single one. But it's good to hear what others are doing.
It'd be also great to have another similar command: "Terminal: Rerun Last Command".
New to VSCode, agree with @thorn0 's suggestion above; wondering how simple it is to make a keybinding, macro, plugin, whatever that achieves the above. effectively focus terminal -> press up arrow key -> press enter -> focus whatever I was on before.
If I could bind that to a key-press, I think it'd save me precious seconds.. thousands of times a day :)
@thorn0 @deanrather Here is a workaround solution.
Step 1: Override the default terminal keybinding from triggering to toggling.
{
"key": "ctrl+`",
"command": "workbench.action.terminal.focus",
"when": "!terminalFocus"
},
{
"key": "ctrl+`",
"command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"
}
Step 2: Override the F5 key, which can be altered to any key combination as you like. On Unix-like OS with X11, the script below checks the focused window and then send key sequences, which will re-run the last command belonging to the last focused terminal, if the focused window is VSCode; otherwise, the F5 key does what it is supposed to do as usual. There should exist some similar method for other OSes.
#!/bin/bash
# Get The Focused Window Name
WNM="$(xdotool getwindowfocus getwindowname)"
if [ -n "$(grep 'Visual Studio Code$' <<< "$WNM")" ]; then
# VSCode: Run The Last Command
xdotool key ctrl+grave Up Return ctrl+grave
else
# Default F5 Behaviour
xdotool key --window "$(xdotool getactivewindow)" F5
fi
Step 3: Register this script in the custom keyboard shortcut, which is in the System Settings on Ubuntu.
Amazing! Thanks @alexr00
Verification steps: Run a task using the Run Task command. Then run the Rerun Task command. Also try specifying runOptions: { reevaluateOnRerun: false } in the task definition and run the Rerun Task command.
Most helpful comment
Thanks for the suggestion @dbaeumer -- Though it doesn't seem to solve the problem I'm looking for. The task I want to re-run is dependent upon both the file and lineNumber. While I'm working in other files I want to keep re-running the previous task and include those previous values and not my current values.
Common problem here is red-green testing where I run a failing test first and then modify the main body of code to fix the test. In the current flow I have to keep switching back to the test to run it which is a lot more time intensive than other platforms I've used for the same purpose (sublime and atom both have plugins for it.)