change hints accept key in VS code - visual-studio-code

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"
}

Related

Bind a command to go to a specific symbol in VS Code

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.

Replace "< -" keystroke combination for a custom shortcut in VS Code

I was wondering how could I set a shortcut, for example CRTL+F for the keystrokes <- for a better experience programming with R language. Or even when I type - it prints out on my coding scripts the full <-.
I could set it in RStudio but couldn't find a way to do that in VS code. The shortcut options in VS Code are always linked to IDE commands, didn't help me at all.
Any ideas?
Or use this handy keyboard shortcut example with arguments from the doc pages
{
"key": "ctrl+f",
"command": "type",
"args": { "text": "<-" },
"when": "editorTextFocus && editorLangId == r"
},
You can also define a user snippet. For example, put this in your snippets\r.json file:
"assign": {
"prefix": "=",
"body": " <- ",
"description": "left arrow assignment"
}
Now, typing =Tab will insert <-.
Got it just by adding the below code to keybinding.json file:
// Place your key bindings in this file to override the defaults
[
{
"key": "oem_minus oem_minus",
"command": "type",
"args": {
"text": "<-"
},
"when": "editorTextFocus"
}
]
Worked perfectly. When I type -- it prints out <-.

vscode custom key binding length issue

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!

Replace with next value (ctrl shift dot) in Visual Studio Code

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" },

Can VS Code type text with keyboard shortcuts?

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": "```"
}
}