Does anyone know how "Replace with next value" (ctr + shift + dot) works ?
I am unable to get this shortcut to do anything on my vscode.
I tried googling examples of this shortcut and asking on vscode gitter/reddit but couldn't get any answers.
It would be greatly appreciated if someone could provide the steps of using this shortcut.
If I press the shortcut after highlighting an integer or float literal (16 or 5.2 for example) it subtracts 1 from it.
Strangely, Replace with Previous Value adds 1 to the value while Replace with Next Value subtracts 1.
I don't know if it has any other purpose.
Add to the accepted answer:
If you use it on a boolean, it toggles between true and false.
No need to "highlight" the number, putting the cursor on it is enough.
As noted by #FĂ©lix Caron, this is how to swap the two keys.
keybindings.json
{ "key": "ctrl+shift+oem_period", "command": "editor.action.inPlaceReplace.up", "when": "editorTextFocus && !editorReadonly" },
{ "key": "ctrl+shift+oem_comma", "command": "editor.action.inPlaceReplace.down", "when": "editorTextFocus && !editorReadonly" },
Moreover, in my case as I have breadcrumbs enabled "breadcrumbs.enabled": true,, the replaceUp key triggered breadcrumbs instead, so I had to unbind it.
{ "key": "ctrl+shift+oem_period", "command": "-breadcrumbs.toggleToOn", "when": "!config.breadcrumbs.enabled" },
{ "key": "ctrl+shift+oem_period", "command": "-breadcrumbs.focusAndSelect", "when": "breadcrumbsPossible" },
Related
My issue:
I would like to bind a few keyboard shortcuts to navigate to specific symbols in my currently open file within VS Code.
Example:
I want to navigate to the symbol <template> by pressing cmd+1.
I want to navigate to the symbol <script> by pressing cmd+2.
I want to navigate to the symbol <style> by pressing cmd+3.
By default, you can do that by pressing cmd+p and then in the palette typing #template which will jump to the template tag within the open file.
So a solution might look something like this in my keybinding.json:
{
"key": "cmd+1",
"command": "workbench.action.gotoSymbol",
"args": ["#template"],
}
However, the args part of this does not work. I'm wondering if anyone knows a good solution for setting up key bindings like this so I can navigate around my files with shortcuts.
Thanks in advance!
Try this:
{
"key": "cmd+1",
"command": "workbench.action.quickOpen",
"args": "#<template>",
},
The command workbench.action.gotoSymbol won't take an argument, but workbench.action.quickOpen will. I don't know why there is that difference, but as you know if you start the Quick Open Panel with # you get object references. And the rest of your text <template> for example will automatically be entered into the input box.
It will filter for those symbols but will not jump to the first one. If you want that additional functionality, you would have to consider a macro which would select the first entry.
There is an alternative that allows you to navigate to anything by using a matching regex. See the extension Select By which allows to jump to any string. For example (in settings.json):
"selectby.regexes": {
"goTo<template>": {
"moveby": "<template>",
}
}
and your keybinding (keybindings.json):
{
"key": "ctrl+1", // <template>`
"command": "moveby.regex",
"args": ["go<template>", "moveby", "next", "start", "wrap"],
// "when": "editorTextFocus && editorLangId == javascriptreact"
}
You can set it up to jump to the previous instance as well:
{
"key": "ctrl+alt+1", // previous <template>
"command": "moveby.regex",
"args": ["goTo<template>", "moveby", "prev", "start", "wrap"],
// "when": "editorTextFocus && editorLangId == javascriptreact"
}
either way it should now "wrap", it just depends on how many <templates> you have in the file and which direction you want to go to first.
I found the solution to my problem, which is pretty funny because it's an existing extension for VS Code that does exactly what I am looking for:
https://marketplace.visualstudio.com/items?itemName=andersonmfjr.vue-jumptotag
To bind the keyboard shortcuts in keybindings.json
{
"key": "cmd+1",
"command": "extension.jumptotemplate",
},
{
"key": "cmd+2",
"command": "extension.jumptoscript",
},
{
"key": "cmd+3",
"command": "extension.jumptostyle",
},
That does exactly what I was looking for.
I want to define a single and universal keyboard binding that allows me to toggle the maximization of the current window, regardless of the type of window.
At a minimum, a window could be:
Any single editor group
The panel itself
By maximization, note that I mean in both height and width so that the window takes over the full application window with the exception of the side bar (i.e. if the side bar is already visible, it remains visible at all times).
By toggling I mean of course going back and forth between the original layout (i.e. remembering it), and the maximization result.
My thinking about this problem
There are several command IDs that I believe could help here but none of them seem to do what I want, e.g.
workbench.action.toggleEditorWidths
workbench.action.maximizeEditor
workbench.action.toggleMaximizePanel
workbench.action.toggleEditorVisibility
I suspect that
there are more commands that could help here
there is probably a way to accomplish this with the right boolean logic of when clauses and joint execution of command IDs (?)
Try this in your keybindings.json (chose your desired keybinding):
{
"key": "alt+m",
"command": "workbench.action.toggleMaximizedPanel",
"when": "terminalFocus"
},
{
"key": "alt+m",
"command": "workbench.action.closePanel",
"when": "editorFocus && panelIsOpen"
},
{
"key": "alt+m",
"command": "workbench.action.togglePanel",
"when": "editorFocus && !panelIsOpen"
},
It works well - has no effect on the SideBar or ActivityBar - except for one thing. The workbench.action.togglePanel command in the third keybinding will appear to toggle the maximized editor but that command shifts focus to the opened panel. Which might not be what your expect.
If you don't want that focus shift to the panel when un-maximizing the editor I think you will have to add a macro to the mix. Disable the second and third keybindings and add this to your settings.json:
"multiCommand.commands": [
{
"command": "multiCommand.toggleEditorWthFocus",
"sequence": [
"workbench.action.togglePanel",
"workbench.action.focusActiveEditorGroup",
"workbench.action.toggleEditorWidths" // will toggle other editor groups width
// but other editor group width goes to a built-in minimum, not 0
]
}
],
using the multi-command macro extension.
and use these as your two keybindings:
{
"key": "alt+m",
"command": "workbench.action.toggleMaximizedPanel",
"when": "terminalFocus"
},
//{
// "key": "alt+m",
// "command": "workbench.action.closePanel",
// "when": "editorFocus && panelIsOpen"
//},
// {
// "key": "alt+m",
// "command": "workbench.action.togglePanel",
// "when": "editorFocus && !panelIsOpen"
// },
{
"key": "alt+m",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.toggleEditorWthFocus" },
"when": "editorTextFocus && !panelIsOpen"
},
I know you said you want the SideBar unchanged, but if you go the macro route I think it would be pretty easy to toggle that as well.
The comments above note that if you have more than one editor group, unfocused editor groups' width will be minimized, but it goes to some built-in minimum and not to 0 width. I don't think there is a way to toggle other editor groups on/off other than by closing other editor groups which can be done but you probably don't want that.
Demo with split:
I am binding custom keys with keybindings.json file like below,
{
"key": "s a",
"command": "workbench.action.files.saveAll",
"when": "vim.mode == 'Normal'"
}, {
"key": "q u",
"command": "workbench.action.closeActiveEditor",
"when": "vim.mode == 'Normal'"
}
It seems that vscode supports only custom keys length to 2.
Is there any way to binding keys (length) more than that?
for example
{
"key": "s a v e",
"command": "workbench.action.files.saveAll",
"when": "vim.mode == 'Normal'"
}, {
"key": "q u i t",
"command": "workbench.action.closeActiveEditor",
"when": "vim.mode == 'Normal'"
}
thank you.
I ran into the same problem but could not find the fix to this issue despite my researches, curious about this one...
Meanwhile, I use a workaround with betterTouchTool for Mac Os and it does the job perfectly (you can assign key sequences per app or globally). For instance I set the key sequence pry to be replaced by binding.pry on the fly (with keybindings.json it was triggered too early, as soon as I hit the 'r'), but you can as well trigger any other action.
I guess it's not the only app allowing this kind of customisation but I use this one a lot and didn't search any further.
Hope this helps!
i new in VS code i want to change hint accept key from "Enter" to "space" and "."
and of course this keys works in normal edit and only works when hint bar is open
i tried something like this on keybinding.json
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "space",
"command": "repl.action.acceptInput",
"when": "parameterHintsVisible"
}
]
but it doesn't work , where i going wrong?
I believe the command you are looking for is acceptSelectedSuggestionOnEnter:
{
"key": "space",
"command": "acceptSelectedSuggestionOnEnter",
"when": "acceptSuggestionOnEnter && editorTextFocus && suggestWidgetVisible"
}
I know you can enter a block of text with code snippets but can you configure keyboard shortcuts to enter some text?
With "editor.action" you can move the cursor but I can't find if it's possible if you can get it to type some text.
Something like Ctrl+Enter would be "); then a new line
Maybe create a code snippet and then invoke it with a keyboard shortcut?
Is there a way to find what all the options are for "editor.action" ?
You can insert a User Snippet on keypress:
Open keybindings.json (Preferences: Open Keyboard Shortcuts (JSON)), which defines all your keybindings, and add a keybinding passing "snippet" as an extra argument
{
"key": "ctrl+enter",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": "\");\n$0"
}
}
Furthermore, you can specify languages in which it should work:
"when": "editorTextFocus && editorLangId == 'javascript'"
See here for more information.
You can also use the simple command type in a keybinding like:
{
"key": "ctrl+enter",
"command": "type",
"args": {
"text": "myText"
},
"when": "editorTextFocus"
},
The list of available keyboard actions is available from here. You can consider to write an extension for VS Code if you have something specific in mind, with that you can create actions with keybindings that modify the editor contents.
I just leave it here. An alias for triple backticks for people with non-English keyboards:
{
"key": "ctrl+shift+1",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus && !editorReadonly && editorLangId == 'markdown'",
"args":{
"snippet": "```"
}
}