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条回答
Emotional °昔
2楼-- · 2020-05-16 13:43

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"
}
查看更多
霸刀☆藐视天下
3楼-- · 2020-05-16 13:45

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

查看更多
狗以群分
4楼-- · 2020-05-16 13:45

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

查看更多
Fickle 薄情
5楼-- · 2020-05-16 13:46

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"
}
查看更多
劳资没心,怎么记你
6楼-- · 2020-05-16 13:49

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

查看更多
The star\"
7楼-- · 2020-05-16 13:50

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

查看更多
登录 后发表回答