145

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.

8
  • 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. Feb 2, 2016 at 21:10
  • 1
    Open in vs code? Like for editing? Open how?
    – rmjoia
    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). 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.
    – rmjoia
    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 :)
    – Jak S
    Mar 9, 2016 at 14:37

11 Answers 11

255

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.

10
  • 5
    +1 But this replaces the existing opened file-tab. Any idea how to open in a new tab, but in the same panel?
    – pavsaund
    Nov 13, 2016 at 19:11
  • 7
    @johnny-oshika You can disable preview behavior in your settings by adding "workbench.editor.enablePreview": false and "workbench.editor.enablePreviewFromQuickOpen": false Feb 27, 2017 at 14:10
  • 3
    @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
    – Brad Cupit
    Nov 3, 2017 at 21:04
  • 7
    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.
    – gerrytan
    Dec 15, 2017 at 3:45
  • They appear to be working on a fix which should be out with the next insiders' release.
    – skube
    Mar 2, 2018 at 21:27
43

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
  • 3
    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. Jun 8, 2019 at 13:10
  • 3
    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
    – iamnotsam
    Jul 22, 2020 at 18:05
  • 1
    Even easier than @iamnotsam ' s answer is to press F1 to open cmd palette in VSCode.
    – Timo
    Mar 25, 2022 at 16:17
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"
}
0
18

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

2
  • 1
    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.
    – Théophile
    Mar 7, 2021 at 17:48
  • 1
    After opening the file, pressing CMD+Shift+E will toggle the focus to your file if you wanted to edit your file Mar 8, 2021 at 22:52
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
  • 1
    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.
    – AdamAL
    Jul 9, 2018 at 13:45
10
  • 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)

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).

0
6

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

0
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

-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
  • hmmm, could it be that you're answering a different question? This question is about opening an existing file. Feb 1, 2017 at 14:57
-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
  • 2
    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. Feb 5, 2016 at 14:22
  • 2
    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
    – pixel 67
    Mar 22, 2018 at 7:25
  • 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
    – Sam J
    Feb 10, 2019 at 23:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.