VSCode: Keyboard shortcuts for modifying user settings - visual-studio-code

I like the idea of CodeLens, VSCode's plugin that tells you reference counts on all your functions & variables. However, when I'm scanning code, the extra vertical margin added to include the "X references" line annoys me enough that I've disabled it. This is a shame, because it's useful information.
I'd like to be able to control whether CodeLens is active via keyboard shortcut. There seem to be no "editor.action.toggleCodeLens" in the keybindings, though, and trying
{ "key": "ctrl+l", "command": "editor.codeLens = false" }
or
{ "key": "ctrl+l", "command": "editor.codeLens = !editor.codeLens" }
produces the error command 'editor.codeLens = false' not found. Is there a way to do this?

Try this extensions: https://marketplace.visualstudio.com/items?itemName=rebornix.toggle
It allows you to setup custom keybindings to toggle any VSCode setting

Related

VS Code when clause context (for keyboard shortcuts) for LaTeX math mode

In VS Code I can define keyboard shortcuts to only work in certain conditions:
https://code.visualstudio.com/api/references/when-clause-contexts
So i can add different variables, e.g. this keyboard shortcut would only work when writing latex documents and the text is focused:
{
"key": "alt+.",
"command": "editor.action.insertSnippet",
"when": "editorLangId == latex && editorTextFocus",
"args": {
"snippet": "\\cdot $0"
}
},
}
Is there any clause context (like "editorTextFocus") that would tell me whether I'm in LaTeX math mode or not that comes with any extension or something (I use the LaTeX Workshop extension)? I haven't found anything online. Or can I define something like this myself? If yes, does anyone know a good resource to find out how to do so?
It is possible to use the extension HyperSnips to create more advanced snippets that only trigger in math-mode (also using regex etc.). Tutorial can be found on their Github. So one could theoretically bind a keyboard shortcut to typing some key or something which then gets auto-expanded by the extension.

VSCode how to know when editor is not split?

Until now, I used cmd+2 to split the editor on Visual Studio Code and then cmd+1 and cmd+2 to move between the split editors. This shortcut stopped working for some reason, and I can't set it on the keyboard shortcut menu either.
I checked with another keyboard, so this is not an hardware issue.
Anyhow, I tried to set new keybindings to split the screen and move between the editors, like this:
[
{
"key": "cmd+shift+]",
"command": "workbench.action.navigateRight",
"when": ""
},
{
"key": "cmd+shift+]",
"command": "workbench.action.splitEditorRight",
"when": ""
},
{
"key": "cmd+shift+[",
"command": "workbench.action.navigateLeft",
},
]
The only problem, I couldn't find what I need to write in the when option.
I want my shortcut to split the editor only if the editor is not split yet, and to move between the editors when it is.
How can I achieve that?
The multipleEditorGroups when clause context returns true when there's more than one editor group open.
You don't need to put a "when" for neither of them. Just checked vscode defaults and they don't have any.

VS Code - find panel/view context name for shortcut 'when' expression

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:
Open the developer tools: Help/Toggle Developer Tools and go to the console
Choose Inspect Context Keys in the VS Code Command Palette
Click on an element in the vscode window
Look in the tools console and expand the last item therein to show all the current context (when clauses).
But 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.

VSCode keyboard shortcut to navigate from search bar to highlighted selection

I'm constantly searching code within a file in VSCode.
Is there a keyboard shortcut to navigate from the search bar to the highlighted selection in the editor? That would make things much more efficient for me.
I know I can copy a highlighted selection from the editor to the search bar using CMD + F.
If you are talking about moving from the find widget to the first match, it looks like you have this option, assuming you don't want to just close the find widget with escape:
the workbench.action.focusActiveEditorGroup command is unbound you could use that. But you have to hit escape twice to unselect the find match if you don't want it to remain selected.
That's a pain though so you might a macro that does it all at once. Like (in settings):
"multiCommand.commands": [
{
"command": "multiCommand.focusEditorFromFind",
"sequence": [
"workbench.action.focusActiveEditorGroup",
"cancelSelection",
"cancelSelection",
]
}
]
and keybindings.json:
{
"key": "shift+e",
"command": "multiCommand.focusEditorFromFind",
"when": "editorFocus && findWidgetVisible"
}
So after typing your find term, just Enter until you get to the particular find match you want to switch focus to, and the Shift+E or whatever keybinding you go with above.
Maybe I am just missing it but it seems odd there isn't an easier way to toggle focus from the find widget.

How to toggle Signature help & intellisense VS Code?

I have VS Code on Win8.1.
I really don't like how the signature box opens up over the surrounding code in the editor. I do like the intellisense box. On the page (link above) it says Ctrl+Shift+Space to manually trigger signature help. But how can I close it? The problem is that it opens up without me triggering it.
I know I can close it by moving the cursor out from the function block. But that is a pain to have to do that all the time. I wish Ctrl+Shift+Space could toggle the box.
I remember when I used Visual Studio. There was a key-short-cut to toggle or to get opacity on the boxes. That was great. Is that possible in VS Code?
It is for JavaScript/React (if that's important)
EDIT:
I found an answer on Reddit that don't give me the good solution Visual Studio has. But it makes the box a bit transparent. But it is always transparent. Here is the solution for the half-way-workaround (cut-and-past from the reddit-post, user: tgreen7):
I found a way to do this in settings. if you go here https://code.visualstudio.com/docs/getstarted/theme-color-reference and search for "editorSuggestWidget.background" that is the setting you are looking to change.
So for example my background was originally the hex color: #21252B
And I changed my settings like so:
"workbench.colorCustomizations": {
"editorSuggestWidget.background": "#21252BAA"
}
and now my suggestion window has opacity. You can adjust the last two digits of the hex number to get your desired transparency (opacity).
escape will close it, and then Ctrl+shift+space to get it back.
If you want a toggle try this with whatever keybinding you want:
{
"key": "ctrl+shift+space", // whatever, even "escape"
"command": "editor.action.triggerParameterHints",
"when": "editorHasSignatureHelpProvider && editorTextFocus"
},
{
"key": "ctrl+shift+space", // use same keybinding as above here fro toggle
"command": "closeParameterHints",
"when": "editorHasSignatureHelpProvider && editorTextFocus && parameterHintsVisible"
},