简体   繁体   中英

vscode: how to clear both the console and the terminal using the same shortcut?

I'm looking for a shortcut that would clear the debug console + the terminal, and that would work when my cursor is on the editor.

I tried this code in the keybindings.json which only works for the terminal, and when the cursor is on the terminal (unless I removed the "when" part). But in any case this doesn't clear the debug console.

{
    "key": "ctrl+k",
    "command": "workbench.action.terminal.clear",
    "when": "terminalFocus"
},
{
    "key": "ctrl+k",
    "command": "workbench.debug.panel.action.clearReplAction",
    "when": "inDebugRepl"
},

You will probably have to use a macro extension like multi-command that will allow you to run multiple commands.

In your settings.json:

"multiCommand.commands": [
  {
    "command": "multiCommand.clearTerminalandDebugConsole",
    "sequence": [
      "workbench.action.terminal.clear",
      "workbench.debug.panel.action.clearReplAction"
    ]
  }
]

and in keybindings.json:

{
  "key": "ctrl+alt+k",
  "command": "extension.multiCommand.execute",
  "args": { "command": "multiCommand.clearTerminalandDebugConsole" },
  // below since you wanted it to work with editor focus
  "when": "editorTextFocus"
},

You used Ctrl - K but that is a sequence used in many already-bound conflicting commands, so I used Ctrl - Alt - K .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM