Reputation: 15654
Is there a shortcut to switch from editor to file explorer (and vice versa) on vscode ? I have yet to find one. Thanks you for your help.
Upvotes: 28
Views: 18863
Reputation: 11
I set up the keyboard shortcut Ctrl
+ \
to quickly switch between the Editor and Explorer.
ctrl
+ shift
+ P
to open command palette
Search : open keyboard shortcut(JSON)
Add the following setting and save file.
[
{
"key": "ctrl+\\",
"command": "workbench.explorer.fileView.focus",
"when": "!filesExplorerFocus"
},
{
"key": "ctrl+\\",
"command": "workbench.action.focusActiveEditorGroup",
"when": "!editorTextFocus"
}
]
Upvotes: 1
Reputation: 642
If anyone is scouring the web for a solution which allows <C-h>
(Ctrl + h
) and <C-l>
(Ctrl + l)
to be used with vim keybindings to easily move from:
This is similar to the functionality I remember when using NerdTree in regular vim
.
Here's my hack:
// keybindings.json (open with Ctrl/Command + Shift + P) and search for JSON
// Keyboard shortcuts
[
// ...snip
// I already remap <C-w> h,j,k,l to <C-h>, <C-j>, etc
{
"key": "ctrl+h",
"command": "workbench.action.focusLeftGroup",
"when": "editorTextFocus && vim.active && vim.mode != 'Insert'"
},
{
// Special case: when in first editor group (pane), go to sidebar
// if visible.
"key": "ctrl+h",
"command": "workbench.explorer.fileView.focus",
"when": "editorTextFocus && vim.active && vim.mode != 'Insert' && activeEditorGroupIndex == 1 && explorerViewletVisible"
},
{
"key": "ctrl+l",
"command": "workbench.action.focusRightGroup",
"when": "editorTextFocus && vim.active && vim.mode != 'Insert'"
},
{
// Special case: when in file explorer, go right (back to 1st open
// editor group)
"key": "ctrl+l",
"command": "workbench.action.focusFirstEditorGroup",
"when": "filesExplorerFocus"
},
// ...snip
]
Note: I had to remove some ctrl + l
keybindings that were floating around in VS Code's keyboard shortcuts before this would work. See item 2 in the list below for help debugging keyboard shortcuts.
Some helpful references I found during my search for answers:
Upvotes: 5
Reputation: 2571
ctrl+shift+e
focuses the file explorer on Windows, and I think cmd+shift+e
focuses the file explorer on on MacOS; but in Ubuntu (at least), ctrl+shift+e
in an editor is the emoji shortcut, which is why I added this chord:
{
"key": "ctrl+alt+r",
"command": "revealFileInOS",
"when": "!editorFocus"
}
The command revealFileInOS
focuses the file explorer at the current file.
To add or change a keyboard shortcut, press ctrl+k
, then ctrl+s
(on Linux or Windows).
To focus an editor pane, use ctrl+N
on Linux or Windows, cmd+N
on a Mac), where N is the pane number starting at 1.
Most commonly, you'll have a single pane, so it would be ctrl+1
on Linux or Windows, cmd+1
on a Mac.
Upvotes: 4
Reputation: 397
For macOS, use shift
+cmd
+E
. Note that if the hotkey is also occupied by another program on your mac, you may need to disable it in the preferences of the program before it tasks effect in VSCode.
Upvotes: 9
Reputation: 3091
Unfortunately Ctrl
+ Shift
+ e
doesn't do the trick for me, as I utilize various vim setups within vscode. This makes working around Ctrl
keys often complex.
I can confirm that @MohamedNaleem's answer works when I turn off various vim integrations. If you don't use vim, I suggest sticking with the built-in.
I use the chord Ctrl
+Space
e
to switch between the explorer and open editors. It feels nice and ergonomic to me -- all I do is hit the Ctrl
and Space
keys together and the e
key quickly afterwards.
Notice the intentionally missing
+
betweenSpace
ande
when notating the chord.
The commands you're looking for are
Explorer: Focus on Folders View
, andView: Toggle Side Bar Visibility
.To change them simply bring up your command pallet (type Ctrl
+ Shift
+ P
), type keyboard
, select Preferences: Open Keyboard Shortcuts
, and input the two shortcut commands above to search.
Double click to select and type your new Ctrl
+ Space
e
chord. Enter
or Return
to confirm. Voila!
Upvotes: 3
Reputation: 466
Please try the View: Show Explorer
shortcut key, ctrl+shift+e.
Upvotes: 45