I frequently want to quickly re-run the last shell command that I used.
I know you can shift focus to the terminal, up arrow and enter but I thought there must be a better way than these three steps.
The sendSequence
command in vscode is getting more powerful and so I looked for a way to create a keybinding that will run the last shell command quickly.
From sendSequence documentation:
Send text from a keybinding
The
workbench.action.terminal.sendSequence
command can be used to send a specific sequence of text to the terminal, including escape sequences. This enables things like sending arrow keys, enter, cursor moves, etc. The example below shows the sorts of things you can achieve with this feature, it jumps over the word to the left of the cursor (Ctrl+Left arrow) and presses backspace:
{
"key": "ctrl+u",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "\u001b[1;5D\u007f" }
}
This feature supports variable substitution.
Note that the command only works with the
\u0000
format for using characters via their character code (not\x00
).
See terminal supports variables substitution:
{
"key": "ctrl+shift+t",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": ". ${file}" }
}
For example, see run files in terminal:
{
"key": "ctrl+shift+t",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "node '${file}'\u000D" }
}