VSCode "Quick Open" menu alters "recently used" ordering too eagerly - visual-studio-code

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

Related

VS Code Each time when I select another file and start to type, I will type in the side bar, not on a page. How to fix it? [duplicate]

I realize that Microsoft had some sort of reason for adding the new "Find" tool in the folder EXPLORER section of VSC.. but... I'm a creature of habit. When I click on a file and then press Ctrl+F, I immediately start typing the value I'm looking for. The results used to look like this in the file editor pane...
But with my last update, when I click on the file in the EXPLORER and press Ctrl+F, I am now getting this NEW small tool in the EXPLORER pane, and the cursor goes THERE. I type away and nothing happens in the file editor until I swear a few near-curse-words and have to click over in the file editor and then press Ctrl+F again and start all over to type the search string. It's bugging me because its old habit.
How can I go back to the old way of how it worked? Is there a simple configuration buried somewhere I can change?
Thanks.
I don't say see a setting to set the old filter-search method as the default in the Explorer. You can disable the list.find command on which the new find widget in the Explorer depends in your keybindings.json which has the effect you want:
{
"key": "ctrl+f",
"command": "-list.find",
// "when": "listFocus && listSupportsFind"
}
Now Ctrl+F with focus in the Explorer will open the editor Find Widget with focus.
But you lose the ability to filter other lists with the Ctrl+F, such as TreeViews (see https://stackoverflow.com/a/73039598/836330 forexample).
The better solution, IMO, is to set up a macro which works when you have explorerFocus and use the Ctrl+F keybinding. You will need a macro extension, like multi-command. Use this keybinding in your keybindings.json:
{
"key": "ctrl+f",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"workbench.action.focusActiveEditorGroup",
"actions.find",
],
"when": "explorerFocus"
},
}
which will switch focus to your current editor and then open the Find Widget therein.
I will provide three steps to achieve this without editing keybindings.json
Step 1: Open keyboard shortcuts
Step 2: Find list.find using the search bar.
Step 3: Change key-binding to f3. If there are multiple bindings f3 and ctrl+f like it was for me, remove ctrl+f key-binding.
Done.
You can open keyboard shortcuts by:
ctrl + k ctrl + s
Open palette ctrl + shift + p, type open keyboard shortcuts.

How to get Visual Studio code to select the correct tab when closing the current tab?

When I close a tab in Visual Studio Code, I would like it to behave like every other tabbed editor/browser I use when closing a tab.
I have already read the answer given to Is there a vscode settings which specifies which tab to open when closing a tab?, which implies that setting "workbench.editor.focusRecentEditorAfterClose": false in settings.json will give the desired behaviour — unfortunately, it does not.
Given five tabs A, B, C, D, E, and that tab C is currently selected:
When I press the close tab shortcut, every other program I've used leaves tab B selected — ie it closes to the left.
Visual Studio Code leaves tab D selected — ie it closes to the right. This drives me mad, as if I close two tabs in succession, the wrong tab is closed for the second close action.
There's nothing particularly wrong about closing to the right instead of the left, except for the fact that virtually every other program closes to the left. It's equivalent to putting a search box on a website and having a search for "foo bar" perform "foo or bar" rather than "foo and bar" — since Google, Bing, DuckDuckGo, eBay, Amazon, Twitter and Facebook (to name but a few major sites) all use and, it needlessly confuses people and slows them down.
I can't find a setting to configure this, nor can I find anything in the Marketplace that might fix it. Is it possible?
You can create your own macro to accomplish what you want. You need a macro because you need to run two commands: close your editor and then focus the editor to the left. I don't believe there is any built-in way to do it otherwise.
So, using a macro extension like multi-command, this goes into your settings:
"multiCommand.commands": [
{
"command": "multiCommand.closeEditorFocusLeft",
"sequence": [
"workbench.action.closeActiveEditor",
"workbench.action.previousEditor",
]
}
]
and a keybinding in keybinding.json:
{
"key": "ctrl+w",
"command": "-workbench.action.closeActiveEditor"
},
{
"key": "ctrl+w",
"command": "extension.multiCommand.execute",
"args": {
"command": "multiCommand.closeEditorFocusLeft"
},
// "when": "editorFocus"
},
I assumed here that you use Ctrl+W to close the active editor, and I first disabled the default command for that and then assigned it to the macro. But you could whatever keybinding you wish. And it works.
In my testing it is required to have the setting
Workbench > Editor: Focus Recent Editor On Close
disabled. So that vscode actually tries to go right instead of to the most recently opened editor wherever that may be (and then go to the left of that).
Unfortunately, outside of an extension, I thinkthis is the only way to accomplish what you want.

Is there a keyboard shortcut to switch between the left-hand side and right-hand side of a diff/compare-two-files editor?

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"

How to open file from VSCode file explorer in same window

Using cmd+shift+e I can highlight the file explorer tab and then use vim keybindings to select a given file. However, I've only figured out how to open a selected file in a new editor pane (Ctrl+Enter).
Is there a shortcut to open it in the same pane? Can I change the behavior of the Ctrl+Enter shortcut? A pointer to the right docs would also be helpful.
This closest action is filesExplorer.openFilePreserveFocus, which is bound by default to Space.
This will open the file currently selected in a new tab, but it won't move your cursor to it.
You can use the cmd+shift+e keybinding to get back to your editor, though!
From the docs
The settings window.openFoldersInNewWindow and window.openFilesInNewWindow are provided to configure opening new windows or reusing the last active window for files or folders and possible values are default, on and off.
If configured to be default, we will make the best guess about reusing a window or not based on the context from where the open request was made. Flip this to on or off to always behave the same. For example, if you feel that picking a file or folder from the File menu should always open into a new window, set this to on.
Note: There can still be cases where this setting is ignored (for example, when using the -new-window or -reuse-window command-line option).
The filesExplorer.openFilePreserveFocus command does what you want with the limitation that it keeps the focus on the explorer sidebar. To move focus to the opened window you can utilize the fact that workbench.view.explorer toggles focus between editor and explorer. Together with a extension such as multi-command that enables running multiple commands the desired behaviour can be achieved:
{
"key": "enter",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"filesExplorer.openFilePreserveFocus",
"workbench.view.explorer",
],
},
"when": "explorerViewletFocus && explorerViewletVisible && !inputFocus"
},

How to reset Visual Studio Code key bindings?

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.