问题
I have the following keybinding in VS code which toggles the position of the cursor between the active document and built-in terminal:
// Toggle between terminal and editor focus
{
"key": "oem_8",
"command": "workbench.action.terminal.focus"
},
{
"key": "oem_8",
"command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"
}
Before i click the shortcut key to move the cursor to the terminal, i first have to save the active file.
I would therefore like to run the file saving command, which after searching on google i believe is :workbench.action.files.save
How would i do this please? i have tried adding the above code snippet at the end of the "command" line but it has not worked.
cheers
回答1:
You would need an extension like macros to run multiple commands from one keybinding.
In your settings.json:
"macros": {
// give it whatever name you what
"saveAndFocusTerminal" : [
"workbench.action.files.save",
"workbench.action.terminal.focus"
]
}
and in your keybindings.json:
{
"key": "oem_8",
// use your name from above here
"command": "macros.saveAndFocusTerminal"
},
EDIT: I don't use the macros
extension anymore, it hasn't been maintained and is missing some crucial functionality. I now use multi-command and there are other macro extensions now.
来源:https://stackoverflow.com/questions/49611435/visual-studio-code-keybindings-running-two-or-more-commands-with-one-shortcut