I want to be able to navigate files in VSCode workspace efficiently via keyboard: exploring the repo by looking at dozens of files before I find a good one.
I can highlight some file in the Folders view by clicking it, then I use arrows to navigate around (so far so good), but when I click Enter, the file is opened and the editor takes focus - which prevents me from navigating the tree further.
Is it possible to configure VSCode so that editor does not take focus after I open it from the sidebar?
The best I found so far is that it is possible to create a key binding to bring back the focus to explorer: ctrl-shift-p > Preferences: Open Keyboard Shortcuts > look for workbench.explorer.fileView.focus (by default there's no key binding assigned).
[EDIT}: As of v1.38 a new command has been added that allows you to open an explorer file and keep focus in the explorer:
Open file and preserve focus
Now it is possible to open the file in preview from the explorer while
preserving the focus in the explorer. The new command is
filesExplorer.openFilePreserveFocus and by default it can be triggered
via the space key.
from open file and preserve focus
[Original answer - now see edit above]
You can do this in one step with a macro extension which enables you to run two commands with the enter key. Here I am using the multi-command extension which has an interval delay option. A 150ms delay between the commands seems necessary to allow the file to be opened before switching focus back to the file explorer.
"multiCommand.commands": [
{
"command": "multiCommand.openFileKeepFocusInExplorer",
"interval": 150,
"sequence": [
"list.select",
"workbench.explorer.fileView.focus",
]
}
]
And then assign a keybinding (in keybindings.json) to that multi-command:
{
"key": "enter",
"command": "multiCommand.openFileKeepFocusInExplorer",
"when": "sideBarFocus && activeViewlet == 'workbench.view.explorer'"
},
In the demo below, I am only using the arrow and enter keys to move between files, open them and keep focus in the file explorer:
Related
When I press Ctrl Tab the windows cycle through most recently used order.
This is winding me up!
So I read up the solution:
To achieve this in Visual Studio Code, you have to edit keybindings.json. Use the Command Palette with CTRL+SHIFT+P, enter "Preferences: Open Keyboard Shortcuts (JSON)", and hit Enter.
Then add to the end of the file:
[
// ...
{
"key": "ctrl+tab",
"command": "workbench.action.nextEditor"
},
{
"key": "ctrl+shift+tab",
"command": "workbench.action.previousEditor"
}
]
That's all good. But then when I try to edit the file, I get this message 'Cannot edit in read-only mode editor'.
OK... so I'll use another editor. I right click on the tab and there is an option 'Open in other editor...' (or something like that). When I click that, nothing happens.
When I search for solutions on 'Cannot edit in read-only mode editor' I get answers to other problems.
I have searched for a file called keybindings.json - can't find it.
Where am I going wrong?
Thanks.
To be able to control the CTRL Tab action
Open the GUI part of the settings responsible for that - Ctrl+K Ctrl+S (the command is named Preferences: Open Keyboard Shortcuts); from there you can either either change those shortcuts or you can open the JSON file (to do the latter you can press Ctrl+O by default or look for the icon in the right end of the tab bar).
As for the JSON, I think the bindings there are evaluated in order (so if you repeat something, the last thing takes precedence) and if you override a default shortcut through the GUI, it would explicitly write a binding that unbinds the command, i.e. same command, but with a minus in front of it.
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.
I frequently have to edit my global settings.json, but not frequently enough to be able to use the open recent menu in VS Code.
Is there a key binding or single button I can press that opens my current settings.json in the current VS Code window? It's irritating to have to keep navigating to /Users/ME/Library/Application\ Support/Code/User/settings.json every time.
Not by default but, if you open up File | Preferences | Keyboard Shortcuts and search for JSON, you'll find there's a Preferences: Open Settings (JSON) item that you can assign a shortcut to.
I've set mine to Alt, to make it similar to Ctrl,, the workbench setting editor.
You can, of course, also store this in your global keybindings.json:
{
"key": "alt+,",
"command": "workbench.action.openSettingsJson"
}
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
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"
},