I simplified my previous answer. Nothing needed in the settings.
You will need a macro extension like multi-command. Using multi-command, make this keybinding:
{
"key": "alt+x", // whatever keybinding you want
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
// you may be able to use this command instead of the sendSquence command, see below
// "workbench.action.terminal.runRecentCommand",
{
"command": "workbench.action.terminal.sendSequence",
// send an uparrow to the terminal shell
"args": {"text": "\u001b[A\u000D"},
},
"workbench.action.focusActiveEditorGroup", // return focus to last active editor
]
},
// if you want this to work only when focus is in an editor
"when": "editorFocus"
}
You can use the following command instead of the sendSquence
command object above
"workbench.action.terminal.runRecentCommand",
if you are using one of the currently supported shells - and you have enabled shell integration - see https://stackoverflow.com/a/55336498/836330 for more on this.
For explanation of the sendSequence
command part above, see https://stackoverflow.com/a/55336498/836330 (Make a keybinding to run previous or last shell commands).