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!
Related
In my previous setup, I was somehow able to remap ²-key (completely useless) into emitting -> (=aka pointer access in C), but I can't find how I did it, neither I can find action in the documentation how to "emit" value upon pressing a key.
How should I do that?
In keybindings.json
{
// "key": "²",
"key": "alt+2",
"command": "editor.action.insertSnippet",
// "when": "resourceExtname == .c", // if you want this
"args": {
"snippet": "->$0"
}
},
I'm not sure how you are inserting the superscript ² which could change the answer, but this example works.
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 <-.
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" },
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": "```"
}
}