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.
I'm trying to have the same command for multiple actions on vscode like run/stop on .py, same on a notebook, but when I add the cmd+enter keybind for one shortcut, the other stops working. I found it pretty random, sometimes it works sometimes not, yesterday it worked and I just opened my project, didn't work...
I've checked the JSON files Default Keyboard Shortcuts (JSON) and Keyboard Shortcuts (JSON) but everything seems to be fine.
Anyone that went through a similar experience or has a fix?
Secondary shortcut may not work because in the json file Keyboard Shortcuts (JSON), when setting a new shortcut, you have a condition where.
This file is the user keybind file and will store all the shortcuts you set or remove. For the removed ones (the default that you change), they have a minus in front of the command name.
To set a new shortcut you need to specify the when.
{
"key": "cmd+enter",
"command": "workbench.action.debug.stop",
"when": "!notebookEditorFocused && inDebugMode"
},
{
"key": "shift+f5",
"command": "-workbench.action.debug.stop",
"when": "inDebugMode && !focusedSessionIsAttach"
}
VSCode by default binds cmd+p to workbench.action.quickOpen. Which is fine. My only issue is that when you confirm a quickOpen on a file using enter it opens the file in a “preview” mode (indicated by the tab’s name having an italic font). This “preview” mode means that if I open two files in a row using cmd+p the action of opening the second will take over the “preview” slot, effectively closing the first file's preview.
VSCode has a setting called workbench.editor.enablePreviewFromQuickOpen which you can use to change this behavior globally. But I don’t want to change it globally. You can also manually move a file out preview mode using workbench.action.keepEditor which is bound by default to cmd+k+enter. But that's an obnoxious extra step.
I would like to selectively decide when I want to open in “preview” mode or in “edit” mode. Ideally I would like to bind something like shift+enter to do this. In my keybindings.json have tried variations on
{
"key": "shift+enter",
"command": "workbench.action.keepEditor",
"when": "inFilesPicker && inQuickOpen"
}
but with no luck :(
The answer to this question ALMOST does what I want:
vscode: Open file instead of previewing file from quick open
The proposed solution of using alt+enter opens the file in a new window. No bueno.
The proposed solution of using the right arrow key to open the file does work... but it does not close the Command Palette like hitting enter does. No bueno.
I do believe you will have to use a macro extension like multi-command. In your settings.json:
"multiCommand.commands": [
{
"command": "multiCommand.openFileNotInPreview",
"sequence": [
"workbench.action.acceptSelectedQuickOpenItem",
"workbench.action.keepEditor",
]
}
]
In keybindings.json some keybinding:
{
"key": "shift+right",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.openFileNotInPreview" },
"when": "inFilesPicker && inQuickOpen"
},
I used "shift+right" here, your "shift+enter" seemed to run into conflicts and would not work.
This will open your selected file in the Ctrl-P panel in a new editor in your same editor group and it will not be in preview mode.
I have been experimenting with my vs-code key bindings.
I would like to reset the key-bindings to the original settings.
How do I do that?
I am on Linux Mint 18.
I tried removing all the records from the keybindings.json
Version 1.34.0 seems to have the settings at a slightly different location:
Click File > Preferences > Keyboard Shortcuts
There is a triple-dot (...) at the top-right hand corner. Click on that and select "Show User Keybindings"
Delete your listed keybindings
Here are the steps to reset the keybindings in VS code.
Click File > Preferences > Keyboard Shortcuts or Press Ctrl+K Ctrl+S
Then, click on keybindings.json
From keybindings.json remove the custom bindings you want to reset.
It seems newer versions of VSCode (>1.33 for Mac) doesn't have a direct link to keybindings.json anymore, as this answer shows. However, there is an option to reset user defined keybindings without mess with files.
Go to the Keyboard shortcuts settings:
There, find the setting tagged as "User". If you click on it with the right mouse button, a context menu will show the option "Reset Keybinding":
This action is gonna reset the selected keybinding and tag it with "Default" again.
first go file > preferences > keyboard shortcuts
you can see all key that you change whit click on triple-dot
or put ( #source:user ) in search bar
now you can right click on which one that you want to reset and select ( reset keybinding )
If you had installed the Keybinding as an Extension e.g Sublime or IntelliJ IDEA Keybindings, simple go to Extension and disable or uninstall it and you would have your default keybinding.
Do we need another answer? Maybe not, but every year or so I find myself sifting through the information on this page, so to make it quicker next time, here are some notes:
To find the location of the settings, you can look for a button/link to the json file located somewhere in Preferences. However, I have found it easier to find the json files on my hard drive than to locate that button/link inside the app (some users report that the button/link is missing in some versions of the app). If your OS does not allow you to search through system files, open a terminal session and type $ locate keybindings.json.
If you can memorize shortcuts, a typical default shortcut that can take you to the button/link is CMD+SHIFT+P. This shortcut opens a box below the main toolbar and you can type "json" in that box to find a button/link to the json file.
General settings are in settings.json
Keyboard settings are in keybindings.json
MacOS: ~/Library/Application Support/Code/User/
Example of keybindings.json
// Place your key bindings in this file to override the defaultsauto[]
[
{
"key": "cmd+r cmd+r",
"command": "workbench.action.reloadWindow",
"when": "isDevelopment"
},
{
"key": "cmd+r",
"command": "-workbench.action.reloadWindow",
"when": "isDevelopment"
},
{
"key": "shift+cmd+c shift+cmd+c",
"command": "workbench.action.terminal.openNativeConsole",
"when": "!terminalFocus"
},
{
"key": "shift+cmd+c",
"command": "-workbench.action.terminal.openNativeConsole",
"when": "!terminalFocus"
},
{
"key": "ctrl+cmd+c",
"command": "editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+shift+alt+cmd+[Minus]",
"command": "-editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "shift+cmd+c",
"command": "editor.action.blockComment",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "shift+alt+a",
"command": "-editor.action.blockComment",
"when": "editorTextFocus && !editorReadonly"
}
]
Note that mapping a key combination that is already in use may result in conflicts. So the best approach is to first remap that default binding to something else. In the above, for instance, the "-" that prefixes "-editor.action.blockComment" serves to suppress the default binding. Thus, you may find that your key bindings are best set in pairs (unless your preferred combinations are sufficiently rare).
Example of settings.json
{
"workbench.colorTheme": "Solarized Light",
"window.zoomLevel": 4,
"workbench.activityBar.visible": false,
"workbench.statusBar.visible": false,
"editor.quickSuggestions": false,
"editor.suggest.snippetsPreventQuickSuggestions": false,
"editor.acceptSuggestionOnCommitCharacter": false
}
Try this documentation page about key binding in VSCode:
https://code.visualstudio.com/docs/getstarted/keybindings
Open a directory that contains user settings (https://code.visualstudio.com/docs/getstarted/settings) and try to remove user key bindings file.
On VS Code version 1.42.1 on Mac you can find a button that opens the Keyboard shortcuts JSON file on the top right corner of the keyboard shortcuts screen which you can open from Code -> Preferences -> Keyboard Shortcuts
For the newer version of VSCode (Version: 1.43.1), you can open the keybindings.json file from the Command Palette (⇧⌘P OR Ctrl+Shift+P) with the Preferences: Open Keyboard Shortcuts (JSON) command.
Once you delete all the data in the keybindings.json file you should get rid of any changes you made to keyboard shortcuts for your installation. Everything would be set back to default.
Reason: The first line in keybindings.json file is a comment // Place your key bindings in this file to override the defaultsauto[], which means if you delete all what is there you'll get the VSCode defaults. (Ref https://code.visualstudio.com/docs/getstarted/keybindings#_advanced-customization)
You can find all information on keybindings here.
For future searchers, since this question refers to Linux, even if the keybindings.json file is moved again one can always just use locate to find it:
$ locate keybindings.json.
Chances are, you will only have one, and if you have more, it will be clear where it is, as it is somewhere inside Code folder.
For example, as of today, mine is here: /home/auser/.config/Code/User/keybindings.json
Going directly to the file, will give you the opportunity to keep what you want and remove what you think might be the problematic setting.
For VSCode Version 1.35.1, which I'm using, one can directly open the keybindings.json file using the button that looks like {} on top-right corner of "Keyboard Shortcuts" Tab's title bar:
Picture showing {} button in top-right corner
Cleaning content of this file cleans all user defined key bindings.
In the latest version, the setting json file is with highlighted button.
I deleted everything in there and it seems to reset all keys.
User setting file
If you are on a Mac, press and hold command while hitting the k and s keys. Then click the icon on the top right with the three circles and press "Show User Keybindings". Then, hit command + delete while highlighting over the keybinding you want to delete.
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!