Between a Code Spell Checker, grammar checking for LaTeX, or refactoring extensions for Python, I get a lot of those blue squiggly lines underneath my code, the ones where you can Quick Fix, by pressing Ctrl + ., and it opens a small menu with options to choose from. I have looking at this very popular article about writing LaTeX in Vim, where you can have a command that Quick Fixes the most recent issue. Is there anyway to do this in VSCode; if yes, anyway to bind to a key binding for easy use?
VSCode 1.71 (Aug. 2022) might help.
See issue 7512
Would be nice if instead of pressing ⌘+. then Enter to apply the quick fix, you could just press ⌘+. two times in a row.
Then, pressing it again could move the cursor to the next (quick fixable) issue, so you could repeatedly fix everything by just pressing ⌘+. several times in a row.
This issue includes:
With the new code action widget, custom keybindings can be utilized to enter the top selected quickfix immediately.
[
{
"key": "ctrl+k",
"when": "CodeActionMenuVisible",
"command": "focusPreviousCodeAction"
},
{
"key": "ctrl+j",
"when": "CodeActionMenuVisible",
"command": "focusNextCodeAction"
},
{
"key": "ctrl+.",
"when": "CodeActionMenuVisible",
"command": "onEnterSelectCodeAction"
},
]
The latter half of this issue, regarding pressing again to move to the next error, is something we can take a look at!
This has been implemented, and released to VSCode Insiders today.
Related
When I step through the the VSCode Quick Open menu, I want it not to automatically switch between editors until I've selected the file I'm interested in (and hit enter). But with a recent (April?) change to VSCode, it automatically shows me each file as I step through the menu. How can I disable that behavior?
Here's my motivation, for those who are interested:
One of the (common?) ways to use VSCode's "Quick Open" menu is to use it like the "last channel" button on a TV remote. I want to open one editor, then open another, and then quickly toggle back and forth between the two. Since they are my current and most-recent editors, they should appear at the top of the Quick Open Menu, so toggling between them is fast.
This used to work just fine, but a recent (April?) change to the Quick Open menu seems to have broken this functionality. Now, it automatically activates the editor for every file that I step through in the menu, changing my "most recent" ordering. It can no longer be used like a "last channel" button.
Here's a short video demonstrating the problem. Here, I'm starting with one.txt. I want to select five.txt via the Quick Open menu, and then quickly toggle between the two. But it opens all the other files along the way!
(In fact, if you watch closely, the behavior is even weirder: It doesn't show me the currently selected file -- it opens the editor for each file as it becomes UN-selected. Maybe this is just a bug?)
FWIW, here are the the relevant parts of my keybindings.json, to make it clear which commands I'm referring to:
// keybindings.json
[
// Trigger quick open menu and pre-select the previously used editor.
// (With either cmd+left/cmd+right)
{
"key": "cmd+left",
"command": "workbench.action.quickOpenPreviousRecentlyUsedEditorInGroup",
"when": "!inEditorsPicker"
},
{
"key": "cmd+right",
"command": "workbench.action.quickOpenPreviousRecentlyUsedEditorInGroup",
"when": "!inEditorsPicker"
},
// Once the menu is open, scan through the choices.
// (Forward with cmd+right, backward with cmd+left)
{
"key": "cmd+left",
"command": "workbench.action.quickOpenNavigatePreviousInEditorPicker",
"when": "inEditorsPicker && inQuickOpen"
},
{
"key": "cmd+right",
"command": "workbench.action.quickOpenNavigateNextInEditorPicker",
"when": "inEditorsPicker && inQuickOpen"
}
]
The issue is that my chosen key binding conflicts with a hard-coded key binding in VSCode. A workaround is to just use a key other than the right arrow.
Explanation here: https://github.com/microsoft/vscode/issues/98479#issuecomment-633378132
I want reload window using shortcut key,
it is already defined to ctrl + R
but dont know how can i reload window using shortcut key.
Can you explain how can i in isDevelopment state?
thanks
Like #scott-schupbach pointed out in the comment, we can guess from issue 81965 on github, that isDevelopment refers to the development tools of vscode. So Ctrl+R only reloads the window when the development tools are active. This question clarifies the use of the development tools.
So the only solution is to rebind the key or remove the isDevelopment condition and rebind the default on Ctrl+R: open recent file.
What I like to do is to press F1 or Ctrl+Shift+P and type in reload window.
Not exactly sure what you are asking, but if I try
{
"key": "alt+m",
"command": "workbench.action.reloadWindow",
// "when": "isDevelopment"
},
that works to reload vscode. If I try to use the when clause, nothing happens - so leave it out if you want to rebind the command. If you also want to unbind the default, use
{
"key": "ctrl+r",
"command": "-workbench.action.reloadWindow",
"when": "isDevelopment"
},
I love using VS Code with the vscode-vim extension as I can do most editing without the mouse. But whenever I'm looking at a diff view (by clicking a file with changes in the SCM/git pane) or an editor that's comparing two files (by running "Compare Active File With..." command), I need to use the mouse to switch between the left and right sides (i.e. the "old" and "new" versions of the change). This is annoying because I frequently compare two files and want to merge them by copying segments with changes from one file to the other, which needs me to switch back and forth in the compare view. Does anyone know if there's a keyboard shortcut, or a command I can bind a new keyboard shortcut to, for this?
Edit (Nov 11, 2020, thanks to #Mark):
workbench.action.compareEditor.focusPrimarySide, workbench.action.compareEditor.focusSecondarySide and workbench.action.compareEditor.focusOtherSide have been added to VS Code. Should be in v1.52
It's an official feature request now, so please upvote it if you want to see this in VS Code:
https://github.com/microsoft/vscode/issues/95068
while changing focus the cursor resets to the previous state for both sides. I found this really annoying. The following keybind resets the cursor to center of the current view while changing focus.
Note: The multi-command extension is required for this.
https://marketplace.visualstudio.com/items?itemName=ryuta46.multi-command
"key": "alt+1",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"workbench.action.compareEditor.focusOtherSide",
{
"command": "cursorMove",
"args": {
"to": "viewPortCenter"
}
}
]
},
"when": "textCompareEditorActive"
Is there any way to set two keyboard shortcuts for one action in VS code? For example, I want to move the cursor to the left by pressing left arrow key or Alt+A.
Is it possible to add multiple keybindings to a shortcut?
Edit: Starting from 1.52 it's possible from keybindings GUI:
What stops you from editing keybindings.json?
{
"key": "left",
"command": "cursorLeft",
"when": "textInputFocus"
},
{
"key": "alt+a",
"command": "cursorLeft"
}
It can be opened from Command Palette Preferences: Open Keyboard Shortcuts (JSON)
Or by clicking the file icon from keybindings GUI page:
Updating the previous answer and adding tiny more details, atleast in the current 2020 version it seems like after changing the keybindings (atleasy cursor up & down), VSCode creates an entry in the JSON file that can be accessed from Alex's answer. The JSON will contain the new entry you made but also the changed entry with a '-' negative sign on the key instruction. Just remove the '-' negative sign and both your keybindings should work like a charm! Obviously don't forget to save!
I'm trying to disable the function in Visual Studio Code where if you don't have a selection highlighted, ctrl+c copies the entire line. I have never tried to do this on purpose, but I am always doing it accidentally when I hit ctrl+c instead of ctrl+v.
Here's what I have tried, which seems like it should work:
Under File->Preferences->Keyboard Shortcuts, there is the default setting:
{ "key": "ctrl+c", "command": "editor.action.clipboardCopyAction",
"when": "editorTextFocus" },
I have attempted to change this, so that it only copies when something is selected, by placing the following in my keybindings.json file:
{ "key": "ctrl+c", "command": "-editor.action.clipboardCopyAction"},
{ "key": "ctrl+c", "command": "editor.action.clipboardCopyAction",
"when": "editorHasSelection" }
I think this should clear the previous binding before re-binding the copy action to only function when something is actually selected. HOWEVER, it doesn't work. The editor still copies a whole line when nothing is selected. If I only have the first line in there, it successfully removes the binding completely, so I know it's doing something, but the "when" tag doesn't seem to be functioning the way it should.
Is there any way to get the editor to do what I want?
In Settings enter the following line:
"editor.emptySelectionClipboard": false
That should do exactly what you want.
Because this comes up on Google as a popular answer...
FYI this is also now a setting in the Settings GUI, search the settings for "empty selection" and it'll narrow it down. Untick to disable and praise your chosen deity.
Even after applying the "editor.emptySelectionClipboard": false setting the problem would persist. I had to remove/edit the project specific settings in the .vscode/ folder within the project folder.