0

Currently in the process of coding MQL4/5 in VSCode because of the awesome extensions. Finding that a few of the (my) most used keyboard shortcuts are actually configurable. Looking for a short answer to emulate the Esc keypress after compiling source. My screen is large and having to hunt down the little x at the lower right corner is the only way I found but not preferable.

Panel is open: Panel open

Press Esc

Terminal closes: Terminal closes

7
  • This question has a bunch of noise like MQL or compiling source, but doesn't quite specify what exactly "closing terminal" is. Closing the whole panel including terminal? Ending the specific terminal session? Closing/hiding just the terminal tab of the panel?I assume the 1st even though it's not "closing terminal" because clicking on some "x" was mentioned, but you need to be as accurate as possible when asking questions.
    – Destroy666
    Commented Nov 30, 2023 at 15:45
  • Simply closing the terminal is enough. What happens is the terminal is launched to execute the compile - then, it retains focus. Once the compile is successful, and the output tab reflects this success, the terminal is no longer needed. I'm new to json/js - and have seen a lot of examples in vscode but haven't been able to connect the dots (yet). If there is quick solution whereby <esc> closes the in-focus terminal, that would be a nice to have. Commented Nov 30, 2023 at 16:01
  • On screenshot you have Output tab focused rather than Terminal. Do you want the keybind to work for both or just Output?
    – Destroy666
    Commented Nov 30, 2023 at 16:11
  • Added a few pics to describe the need. Thanks for the advice! Hope this helps. Commented Nov 30, 2023 at 16:12
  • I would like the entire frame to be closed as if the closing 'x' was pressed. Commented Nov 30, 2023 at 16:16

2 Answers 2

2

To close the entire panel if it has focus, you can use this keybind in your keybindings.json:

    {
        "key": "escape",
        "command": "workbench.action.closePanel",
        "when": "panelFocus"
    }

This will work problemlessly with most panel tabs, like Output. It might not work with Terminal if your setup is passing key presses to terminal. If so, you need to look at terminal.integrated.commandsToSkipShell setting and add workbench.action.closePanel there.

You should also check out:

Note: You can review the full set of VS Code commands via the Keyboard Shortcuts editor File > Preferences > Keyboard Shortcuts. The Keyboard Shortcuts editor lists all commands built into VS Code or contributed by extensions, along with their keybindings and visibility when clauses.

2
  • Thanks for the hints. Works now - just had to configure the when clause correctly. The when clause = "when": "focusPanel=Terminal" Commented Dec 2, 2023 at 7:34
  • Not sure what you mean by statement above. If it's only terminal (which is not according to comments) then it would be terminalFocus rather than that. But glad it helped
    – Destroy666
    Commented Dec 2, 2023 at 12:27
0

If you're using vim mode, you need to add a when context like this:

    {
        "key": "escape",
        "command": "workbench.action.closePanel",
        "when": "view.terminal.visible"
    }

Without this you never went out of insert mode using escape key.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .