129
votes

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.

11
By their documentation, I think that the only way is to right click and select Reveal in Finder (ou can also navigate to the location of a file or folder in the native Explorer by right-clicking on a file or folder and selecting Reveal in Explorer (or Reveal in Finder on the Mac).) The Basics and Key Bindingsrmjoia
@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.Johnny Oshika
Open in vs code? Like for editing? Open how?rmjoia
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).Johnny Oshika
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

11 Answers

229
votes

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.

28
votes

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"
  }
26
votes

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"
}
12
votes

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

11
votes

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"
}
9
votes

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

6
votes

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

2
votes

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

2
votes
  • 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)

-1
votes

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

-3
votes

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