I am working on OS Ubuntu 22.04 running inside a Virtualbox VM hosted in a windows 10 OS.
Inside the VM, it seems that my VScode has reset some of the user-defined keyboard shortcuts I have previously set.
So I want to re-define them.
I want to change the keyboard shortcut of "Toggle Line Comment", which is set from CTRL + Y to CTRL + ù ( currently CTRL + Y is assigned by the system to "redo", and that is OK ).
So I click on the pencil icon of "Toggle Line Comment",
press the keys combination CTRL + ù
"ù" gets interpreted as "[Backslash]"
press enter
but then I still see assigned CTRL + Y (as if the change was rejected); and from some tests I did, that one is the only combination that manages to toggle comment lines.
I have tryed to restart VScode but nothing changes, I cannot edit the settings from the UI.
So I have tryed to edit them from the keybindings.json
tommaso#tommaso-VirtualBox02:~$ sudo locate keybindings.json
/home/tommaso/.config/Code/User/keybindings.json
tommaso#tommaso-VirtualBox02:~$ vim /home/tommaso/.config/Code/User/keybindings.json
And the content of the opened file is
[
{
"key": "ctrl+alt+[Backslash]",
"command": "editor.action.blockComment",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+shift+a",
"command": "-editor.action.blockComment",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+shift+7",
"command": "-editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+[Backslash]",
"command": "editor.action.commentLine"
}
]
It is indeed strange that the last {} entry I have added via the UI is missing the "when" key.
Anyway I have edited the content to
[
{
"key": "ctrl+alt+[Backslash]",
"command": "editor.action.blockComment",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+shift+a",
"command": "-editor.action.blockComment",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+shift+7",
"command": "-editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+[Backslash]",
"command": "editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
}
]
saved,
restarted VScode
but again, the "toggle line comment" gets activated only by CTRL + Y.
The strange thing is that the CTRL + ALT + ù, that is
{
"key": "ctrl+alt+[Backslash]",
"command": "editor.action.blockComment",
"when": "editorTextFocus && !editorReadonly"
}
works fine.
It is like VS code cannot load changes from keybindings.json .
What can be blocking the edit?
I believe you would do this like so:
[
{
"key": "ctrl+\\",
"command": "editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+y",
"command": "-editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
},
]
From another machine having the same key VScode shortcut configuration, and having the shotcuts properly working on VScode, I accessed the content of keybinding.json, and it is the following
// Place your key bindings in this file to override the defaultsauto[]
[
{
"key": "ctrl+shift+[Backslash]",
"command": "editor.action.blockComment",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+shift+a",
"command": "-editor.action.blockComment",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+[Backslash]",
"command": "editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+shift+7",
"command": "-editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
}
]
It is exactly the same content of the one on the other machine, for which it was not working properly.
So the problem is machine-related.
So the end I have set the key combination ctrl+à for the toggle line comment, and it is OK.
I think the problem is somehow linked to how VScode interprets a key:
I have an italian keyboard having a key which contains "§" and "ù", but VS code somehow interprets it as "[Backslash]".
Once again I want to underline that it is strange to me that
ctrl+alt+ù
is correctly got as change by VScode, while
ctrl+ù
is rejected ( the UI swithces the combination automatically to "ctrl"+"y", while on the keybindings.json it is actually written "ctrl+[Backslash]" )
even if in both cases 1) and 2), "ù" is interpreted as "[Backslash]".
Related
VScodevim has extension.vim_ctrl+j by default mapped to Ctrl+j which allows you do navigate down pop-up code suggestion windows (triggered by hitting Ctrl+Space in insert mode) like this:
It also has extension.vim_ctrl+k mapped to Ctrl+k but this binding down not work, so I cannot scroll up pop-up code suggestion windows. in insert mode defaults to entering a digraph but simply adding something like this
{
"before": ["<C-k>"],
"after": ["extension.vim_ctrl+k"]
}
to my settings.json does not work since although it removes the digraph functionality, from what I understand, whenever I now press Ctrl+k in insert mode, VSCode will consult the settings.json, find the mapping of to "extension.vim_ctrl+k" which points it back to settings.json in a sort of infinite loop.
:h i_ctrl-j in vim reveals this keybind to be mapped to "Begin new line" so it seems VScode interprets "Begin new line" as navigating down a pop-up window in insert mode instead of it's usual vim behaviour of creating a new line and moving the cursor there, although not sure this is how it works. In any case, I could not find an equivalent vim command that perhaps VSCode could use to scroll up in pop-up windows. Any help would be much appreciated!
I got this working by copying the existing default keybinds for ctrl+p and ctrl+n which are used throughout VSCode by default for scrolling up and down.
I've used alt here in my keybinds.json file but you can easily replace it with ctrl to achieve what you want
keybinds.json
// Down Motion
{
"key": "alt+j",
"command": "cursorDown",
"when": "textInputFocus"
},
{
"key": "alt+j",
"command": "showNextParameterHint",
"when": "editorFocus && parameterHintsMultipleSignatures && parameterHintsVisible"
},
{
"key": "alt+j",
"command": "selectNextSuggestion",
"when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
},
{
"key": "alt+j",
"command": "list.focusDown",
"when": "listFocus && !inputFocus"
},
{
"key": "alt+j",
"command": "workbench.action.quickOpenSelectNext",
"when": "inQuickOpen"
},
// Up Motion
{
"key": "alt+k",
"command": "cursorUp",
"when": "textInputFocus"
},
{
"key": "alt+k",
"command": "showPrevParameterHint",
"when": "editorFocus && parameterHintsMultipleSignatures && parameterHintsVisible"
},
{
"key": "alt+k",
"command": "selectPrevSuggestion",
"when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
},
{
"key": "alt+k",
"command": "list.focusUp",
"when": "listFocus && !inputFocus"
},
{
"key": "alt+k",
"command": "workbench.action.quickOpenSelectPrevious",
"when": "inQuickOpen"
}
In VS2017 when use Ctrl+Del to delete a word, it will auto delete any following whitespaces.
Is it available to config VSC to working same way?
I don't think there is any built-in setting to do that. You would either have to just hit Ctrl-Del twice
or set up a macro to run that command twice.
Using the multi-command macro extension, puth is into settings.json:
"multiCommand.commands": [
{
"command": "multiCommand.deleteWordAndWhieSpaceRight",
"sequence": [
"deleteWordRight",
"deleteWordRight",
]
}
]
and in keybindings.json:
{
"key": "ctrl+delete",
"command": "-deleteWordRight",
"when": "textInputFocus && !editorReadonly"
},
{
"key": "ctrl+delete",
"command": "multiCommand.deleteWordAndWhieSpaceRight",
"when": "textInputFocus && !editorReadonly"
},
Like in vim nerd tree plugin, when you push 'm' then 'a' button in vim nerd tree you can add file in current directory where cursor on Nerd tree. Is it possible do it in vs code? Maybe some plugins?
Unfortunately there is no such plugin yet but you could define some customized keybindings which resembles NERDTree to some extent ( File > Preferences > Keyboard Shortcuts and click on the link keybindings.json ):
[
{
"key": "f",
"command": "explorer.newFile",
"when": "explorerViewletFocus && !inputFocus"
},
{
"key": "d",
"command": "explorer.newFolder",
"when": "explorerViewletFocus && !inputFocus"
},
{
"key": "x",
"command": "deleteFile",
"when": "explorerViewletFocus && !inputFocus"
},
{
"key": "r",
"command": "renameFile",
"when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"
},
{
"key": "enter",
"command": "list.select",
"when": "listFocus && !inputFocus"
},
{
"key": "o",
"command": "list.select",
"when": "listFocus && !inputFocus"
}
]
You could change the keys freely and commands are self explanatory. i. e: hitting f in explorer will add a file in selected directory and ... ).
Fortunately we also have j and k movements in explorer via vscodevim plugin.
The only missing part is searching the tree; and of course there is a promise to be added by January 2019 ( see issue #10026 )
How can I change snippet trigger key to Ctrl+k? I tried these settings (from default keybindings file):
{
"key": "ctrl+k",
"command": "insertSnippet",
"when": "config.editor.tabCompletion && editorTextFocus && hasSnippetCompletions && !editorTabMovesFocus && !inSnippetMode"
}
but it doesn't work as expected, i.e. nothing happens.
I want to have this workflow:
type log in javascript file and hit Ctrl+k.
vscode looks for a log snippet and if it exist then expand snippet.
type something at current tabstop, hit Ctrl+k to go to another tabstop point.
For the last step there are jumpToNextSnippetPlaceholder command. But I'm stuck with initial action on first step. Can anyone help?
Cheers!
So, I investigated some time in reading documentation and ended up with following preferences (keybindings.json):
{
"key": "ctrl+k",
"command": "insertSnippet"
},
{
"key": "ctrl+k",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus && editorHasSelection"
},
{
"key": "ctrl+k",
"command": "jumpToNextSnippetPlaceholder",
"when": "editorTextFocus && inSnippetMode"
},
{
"key": "shift+ctrl+k",
"command": "jumpToPrevSnippetPlaceholder",
"when": "editorTextFocus && inSnippetMode"
}
Maybe it could help anyone.
Introduction
I am creating an extension in Visual Studio Code that creates a 'quickPick' menu from which the user can select options:
I can use the up and down arrows to scroll through the list, but I want to be able to bind this to something more home-row friendly like ctrl-n and ctrl-p. I have ctrl-n and ctrl-p already bound for scroll up/down on the main command menu (ctrl-shift-p), and I was hoping the quick pick would fall under this rule as well. Unfortunatley, none of my many ctrl-n context bindings are taking effect.
I'm hoping for something I can add to 'keybindings.json' that looks something like:
{
"key": "ctrl+n",
"command": "cursorDown",
"when": "quickPickFocus"
},
But I can't see anything like this when browsing through the "Default Keyboard Shortcuts".
Questions
How do you create key bindings for quick pick lists?
Can I possibly create a custom "when" context for my extension? Then I can specify something like:
"when" : "myExtensionIsActive && blah"
Additional Doc
Here are all the overridden ctrl-n key bindings in my keybindings.json:
{
"key": "ctrl+n",
"command": "cursorDown",
"when": "editorTextFocus"
},
{
"key": "ctrl+n",
"command": "workbench.action.quickOpenNavigateNext",
"when": "inQuickOpen"
},
{
"key": "ctrl+n",
"command": "showNextParameterHint",
"when": "editorTextFocus && parameterHintsVisible"
},
{
"key": "ctrl+n",
"command": "selectNextQuickFix",
"when": "editorFocus && quickFixWidgetVisible"
},
{
"key": "ctrl+n",
"command": "selectNextSuggestion",
"when": "editorTextFocus && suggestWidgetVisible"
},
Here is the code where I create the quickPick:
var themeList = this.getThemeList()
vscode.window.showQuickPick(themeList)
.then(val => {
// Update the status bar
this.cmdChannel.text = `Theme: ${val}`
this.cmdChannel.show();
});
You just add wrong key binding command and when, please try to add this to your keybindings.json
{
"key": "ctrl+n",
"command": "workbench.action.quickOpenSelectNext",
"when": "!editorFocus"
},
{
"key": "ctrl+p",
"command": "workbench.action.quickOpenSelectPrevious",
"when": "!editorFocus"
}