150

When using VSCode on Windows, I can navigate the file explorer and hit Enter on the focused file and the file will open in the editor. On my Mac, however, when I do this, VSCode will open the rename input as follows:

enter image description here

I'm not sure why it does this. Even in other text editors (e.g. Atom), the default behavior is to open the file on Enter. Is there any way to change this behavior so that the file opens on Enter? The only workaround I've found so far is CTRL+Enter, which opens the file in a new pane, but with a 3 pane limit in VSCode, this is quite limiting.

7
  • 1
    @rmjoia Sorry I wasn't clear. I'm not trying to reveal a file in Explorer or Finder. I just want to open the file. When I click Enter, VSCode wants me to rename the file on Mac. I don't want to rename the file, I just want to open it. It works as expected in Windows but not Mac. Commented Feb 2, 2016 at 21:10
  • 1
    Open in vs code? Like for editing? Open how? Commented Feb 2, 2016 at 21:32
  • 2
    Yes, I just want to open the file in VSCode for editing without taking my fingers off the keyboard. I do it all of the time in Atom, Visual Studio, and even VSCode for Windows, but I can't seem to do it in VSCode for Mac. It keeps trying to rename the file when I hit enter (per my screenshot above). Commented Feb 2, 2016 at 22:39
  • 1
    Ok, I'm removing my answer then, since it doesn't add anything to the question. I would recommend to use the VSCode forum to request as a feature or maybe get a hint from the community. Commented Feb 3, 2016 at 14:53
  • 3
    An explanation for this behaviour is that 'Enter' is the shortcut in OS X to rename a file - try it in Finder :) Commented Mar 9, 2016 at 14:37

13 Answers 13

257

If anyone else comes across this problem, the keyboard shortcut to open a file from the file explorer in VSCode on a Mac is:

CMD+Down

This also works in Finder.

Sign up to request clarification or add additional context in comments.

10 Comments

+1 But this replaces the existing opened file-tab. Any idea how to open in a new tab, but in the same panel?
@johnny-oshika You can disable preview behavior in your settings by adding "workbench.editor.enablePreview": false and "workbench.editor.enablePreviewFromQuickOpen": false
@DimaKuzmich that worked great! Setting just the first one, "workbench.editor.enablePreview": false, was enough to make it open each file in its own tab
Thanks, I wonder why they made this so hard to figure out. I can't even find a command for Cmd + Down in the command list.
They appear to be working on a fix which should be out with the next insiders' release.
|
48

I ended up compiling a few solutions here together to get the following keybinding.json editions (Open via Code > Preferences > Keyboard Shortcuts > keybindings.json):

 { "key": "cmd+enter", "command": "renameFile", "when": "explorerViewletVisible && filesExplorerFocus" }, { "key": "enter", "command": "-renameFile", "when": "explorerViewletVisible && filesExplorerFocus" }, { "key": "enter", "command": "list.select", "when": "listFocus && !inputFocus" } 

3 Comments

This makes the explorer window completely navigable. Now I don't have to click to navigate the file-tree. I just CMD-SHIFT-E from the editor to shift focus over to the file explorer, arrow-key over to another file, and press enter to open the file and shift focus back to the editor. Perfectly intuitive. Thank you.
If you are like me you just want to put this in a JSON file.... command + shift + p opens up command palette and search for "Preferences: Open Keyboard Shortcuts (JSON)" and that leads to this file
Even easier than @iamnotsam ' s answer is to press F1 to open cmd palette in VSCode.
28

In version 1.19.2, on the mac I was able to go to keyboard shortcuts (menu bar > code > preferences > keyboard shortcuts), search for "rename," and edit "renameFile" ("When" value is "explorerViewletVisible && filesExplorerFocus && !inputFocus") changing the shortcut to "cmd+enter."

You can also past the following in your keybindings.json (there's a link to it on the keyboard shortcuts page):

{ "key": "cmd+enter", "command": "renameFile", "when": "explorerViewletVisible && filesExplorerFocus && !inputFocus" } 

Enter now opens the highlighted file in the explorer and ctrl+enter puts it in rename/edit mode.


–Edit–

After I upgraded to 1.21.0 the enter key started functioning as renameFile again. cmd+enter still functioned as renameFile as well. To fix this either go to menu bar > code > preferences > keyboard shortcuts and right-click the offending entry and remove it or add a hyphen/minus sign to the beginning of the command in keybindings.json:

{ "key": "enter", "command": "-renameFile", "when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !inputFocus" } 

Comments

20

On my Mac, simply hitting the Spacebar opens the file for me.

2 Comments

Spacebar opens the file but keeps focus on the Explorer. This would be useful for opening a few different files without having to switch back and forth, but it's different from the command that opens the file and focuses on the editor.
After opening the file, pressing CMD+Shift+E will toggle the focus to your file if you wanted to edit your file
13
  • SPACE: open but keep focus on Explorer (filesExplorer.openFilePreserveFocus command)
  • CMD+Down: open and focus the opened file (explorer.openAndPassFocus command)

You can change them in "Code - Preferences - Keyboard Shortcuts": Keyboard Shortcuts (Code - Preferences - Keyboard Shortcuts)

Comments

11

So I ran into this as well, but the keyboard shortcuts that I ended using is to map cmd+enter to rename and removing the renameFile from enter.

{ "key": "cmd+enter", "command": "renameFile", "when": "explorerViewletVisible && filesExplorerFocus" }, { "key": "enter", "command": "-renameFile", "when": "explorerViewletVisible && filesExplorerFocus" } 

1 Comment

This didn't work for me. The slightly longer negated binding from bkidd's answer is what was produced in the keybindings.json after choosing "remove" using the GUI-editor. This worked for me in VSCode 1.24.1.
9

cmd+down does NOT work for me using VSCode 1.10.2 on Mac 10.10.5.

However, cmd+enter does work for me.

Or if you want to set your own keybinding to open a file from File Explorer, add these lines to your keybindings.json:

// open file from File Explorer { "key": "enter", "command": "list.select", "when": "explorerViewletVisible && filesExplorerFocus" }, 

(Of course, you can change enter to any key combination you want).

Comments

7

I tried to remove the shortcut of "Rename", which has the Keybinding of "Enter". Then it opens the file properly when I press "Enter".

Comments

2

For me, I have to do command 0 and then do a command down This brings me to the explorer and then opens the file I select. In Atom, I just had to hit enter to open the file, I find this to be a strange behavior. vscode v 1.21.1 on OSX

Comments

1

If you are using VSCodeVim extension, you also can press l key, when jumping by j and k

2 Comments

Can you elaborate? j and k don't allow me to navigate up and down the solution explorer.
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0

When opening a file from the explorer you may want to consider adding a binding for the explorer.openAndPassFocus shortcut, which solves the original poster's issue of opening the file in a new pane.

vs code shortcut for opening file from explorer

Comments

-1

In preferences:

Code -> Preferences -> Keyboard Shortcuts

Add this to your keybindings.json

{ "key": "ctrl+n", "command": "workbench.action.files.newFile" } 

within the array that may or may not contain other keybindings you have set. Save keybindings.json

Then when you navigate to a directory in the file explorer, you can create a new file with ctrl+n

1 Comment

hmmm, could it be that you're answering a different question? This question is about opening an existing file.
-3

Not sure why the "enter" behavior is different, I am not sure "enter" alone is set in the keybindings on your system or its just defaults to different behaviors based on OS standards...

The good news is, what you are looking for is CTRL+P or CTRL+O

CTRL+P let's you find a file, and CTRL+O should open it (the exact behavior you'd like)

You may also be able to add "Enter" as a possibility for the "workbench.action.files.openFile" command, but not sure if that will break anything if you do. Try it, or just get used to using CTRL+O on both platforms!

More info:

https://code.visualstudio.com/Docs/customization/keybindings

3 Comments

I use CTRL+P quite extensively, but sometimes I want to navigate the file explorer (CMD+0 or CMD+SHIFT+E) and then open a file, all using the keyboard. Strangely, this doesn't seem possible on the Mac.
Me too @JohnnyOshika, I'm a VIM user and I'm used to having nerd commenter that displays a sidebar with the file structure like sublime or Atom. I guess I have to get used to using vscode
I'm in the same boat as @JohnnyOshika - I usually use CTRL+P, but sometimes want to use the explorer view to navigate then open the file

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.