VSCode: Open file from file explorer with Enter key on Mac OSX

Visual Studio-Code

Visual Studio-Code Problem Overview


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.

Visual Studio-Code Solutions


Solution 1 - Visual Studio-Code

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.

Solution 2 - Visual Studio-Code

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

Solution 3 - Visual Studio-Code

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

Solution 4 - Visual Studio-Code

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

Solution 5 - Visual Studio-Code

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

Solution 6 - Visual Studio-Code

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

Solution 7 - Visual Studio-Code

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

Solution 8 - Visual Studio-Code

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

Solution 9 - Visual Studio-Code

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

Solution 10 - Visual Studio-Code

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

Solution 11 - Visual Studio-Code

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJohnny OshikaView Question on Stackoverflow
Solution 1 - Visual Studio-CodeJohnny OshikaView Answer on Stackoverflow
Solution 2 - Visual Studio-CodeMor ShemeshView Answer on Stackoverflow
Solution 3 - Visual Studio-CodebkiddView Answer on Stackoverflow
Solution 4 - Visual Studio-Codeifedapo olarewajuView Answer on Stackoverflow
Solution 5 - Visual Studio-CodeMikeView Answer on Stackoverflow
Solution 6 - Visual Studio-CodewisbuckyView Answer on Stackoverflow
Solution 7 - Visual Studio-CodeLucas PotterskyView Answer on Stackoverflow
Solution 8 - Visual Studio-CodeartecherView Answer on Stackoverflow
Solution 9 - Visual Studio-Codepixel 67View Answer on Stackoverflow
Solution 10 - Visual Studio-CodepriortdView Answer on Stackoverflow
Solution 11 - Visual Studio-CodeTobiah ZarlezView Answer on Stackoverflow