visual studio code keybindings - Running two or more commands with one shortcut

时光毁灭记忆、已成空白 提交于 2019-12-14 03:43:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!