I'm trying to add some shortcuts to my VS Code instance and I want to scope them using the when
expression to avoid conflicts.
Alas, I'm struggling to find the right context name to use in the expression to achieve what I want.
I've searched the documentation and found that a number of them are listed here: https://code.visualstudio.com/docs/getstarted/keybindings#_contexts
But, as the documentation says:
The list above isn't exhaustive and you may see some when contexts for specific VS Code UI in the Default Keyboard Shortcuts.
Of course, the context to which I want to scope my shortcuts is not on the list ;)
Thus, I was wondering if there was a way to find the context name of a specific panel/view in the VS Code UI.
To illustrate this, suppose I'd like to make a shortcut active only when the panel that lists the available NPM scripts is focused... What context name should be used to achieve that?
I tried this - not expecting it to work - but it seems to:
"when": "focusedView == npm"
Similar info is active/focussed view context clauses.
In general, you can:
Help/Toggle Developer Tools
and go to the consoleInspect Context Keys
in the VS Code Command PaletteBut when I did that I didn't find anything helpful and focusedView = ""
was there, so that's not helpful.
so I just tried
{
"key": "alt+i",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "howdy" },
"when": "focusedView == npm"
},
that just prints howdy
to the terminal for testing.. And the only way I could get it to work was when the npm scripts
viewlet header or its contents had focus.