VSCode: Open file from file explorer with Enter ke

2020-05-16 13:01发布

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.

10条回答
\"骚年 ilove
2楼-- · 2020-05-16 13:50

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

查看更多
Melony?
3楼-- · 2020-05-16 13:52

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.

查看更多
够拽才男人
4楼-- · 2020-05-16 14:03

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

查看更多
放荡不羁爱自由
5楼-- · 2020-05-16 14:04

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"
  }
查看更多
登录 后发表回答