VSCode: 在 Mac OSX 上使用 Enter 键从文件资源管理器打开文件

在 Windows 上使用 VSCode 时,我可以在文件资源管理器中导航,并在焦点文件上按 Enter,文件将在编辑器中打开。然而,在我的 Mac 上,当我这样做时,VSCode 将打开重命名输入,如下所示:

enter image description here

我不知道为什么会这样。即使在其他文本编辑器(例如 Atom)中,默认行为也是在 Enter上打开文件。有什么办法可以改变这种行为,使文件在 Enter上打开?到目前为止我发现的唯一解决方案是 CTRL + Enter,它在一个新窗格中打开文件,但是在 VSCode 中有3个窗格的限制,这是相当有限的。

28860 次浏览

不知道为什么“输入”的行为是不同的,我不确定“输入”是单独设置在您的系统上的键绑定或它只是默认为不同的行为基于操作系统标准..。

好消息是,您正在寻找的是 CTRL + P 或 CTRL + O

CTRL + P 让您找到一个文件,CTRL + O 应该打开它(按照您希望的确切行为)

您也可以添加“ Enter”作为“ workbench.action.files.openFile”命令的一种可能性,但是不确定如果这样做是否会破坏任何东西。 尝试一下,或者习惯在两个平台上都使用 CTRL + O!

更多信息:

Https://code.visualstudio.com/docs/customization/keybindings

如果其他人遇到这个问题,在 Mac 上用 VSCode 从文件浏览器打开文件的快捷键是:

CMD + Down

这也适用于 Finder。

偏好:

代码-> 参数设置-> 键盘快捷键

把这个添加到 keybindings.json

{


"key": "ctrl+n",
"command": "workbench.action.files.newFile"
}

在可能包含也可能不包含已设置的其他键绑定的数组中。 保存 keybindings.json

然后,当您导航到文件资源管理器中的一个目录时,您可以使用 ctrl + n 创建一个新文件

使用 Mac 10.10.5上的 VSCode 1.10.2,cmd+down对我不起作用。

然而,cmd+enter确实为我工作。

或者,如果您想设置自己的密钥绑定来从文件资源管理器打开一个文件,请将以下行添加到您的 keybindings.json:

// open file from File Explorer
{ "key": "enter", "command": "list.select",
"when": "explorerViewletVisible && filesExplorerFocus" },

(当然,您可以将 enter更改为您想要的任何键组合)。

所以我也遇到了这种情况,但是我最后使用的键盘快捷键是映射 cmd+enter以重命名并从 enter中删除 renameFile。

{
"key": "cmd+enter",
"command": "renameFile",
"when": "explorerViewletVisible && filesExplorerFocus"
},
{
"key": "enter",
"command": "-renameFile",
"when": "explorerViewletVisible && filesExplorerFocus"
}

在1.19.2版本中,我可以在 Mac 上进入键盘快捷键(菜单条 > 代码 > 首选项 > 键盘快捷键) ,搜索“重命名”,并编辑“ renameFile”(“ When”值为“ ExplorerViewletVisible & & filesExplorerFocus & & !“ inputFocus”)将快捷方式更改为“ cmd + enter”

您也可以在 keybindings.json 中通过以下内容(在键盘快捷方式页面上有一个链接) :

{
"key": "cmd+enter",
"command": "renameFile",
"when": "explorerViewletVisible && filesExplorerFocus && !inputFocus"
}

现在,Enter 将在资源管理器中打开突出显示的文件,ctrl + Enter 将其置于重命名/编辑模式。


- 编辑-

在我升级到1.21.0之后,Enter 键又开始作为 renameFile 运行了。Cmd + enter 仍然可以作为 renameFile 使用。要解决这个问题,可以进入菜单栏 > 代码 > 首选项 > 键盘快捷键,右键单击违规条目并删除它,或者在 keybindings.json 命令的开头添加一个连字符/减号:

{
"key": "enter",
"command": "-renameFile",
"when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !inputFocus"
}

对我来说,我必须先做 command 0,然后再做 command down 这将我带到资源管理器,然后打开我选择的文件。 在 Atom 中,我只需要点击 enter打开文件,我发现这是一个奇怪的行为。vscode v 1.21.1OSX

我试图删除“重命名”的快捷方式,其中有“回车”的键绑定。然后,当我按下“回车”时,它会正确地打开文件。

最后,我在这里汇编了一些解决方案,得到了以下 keybinding.json版本(通过 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"
}

在我的 Mac 上,只需点击空格键就可以打开文件。

  • 打开,但是集中精力在探索者上 (filesExplorer.openFilePreserveFocus命令)
  • 打开 聚焦打开的文件(explorer.openAndPassFocus命令)

你可以在“代码偏好-键盘快捷键”中更改它们: Keyboard Shortcuts (Code - Preferences - Keyboard Shortcuts)