在Windows上使用VSCode时,我可以浏览文件资源管理器并在焦点文件上按Enter键,文件将在编辑器中打开。但是,在我的Mac上,当我这样做时,VSCode将打开重命名输入,如下所示:
我不确定为什么会这样做。即使在其他文本编辑器(例如Atom)中,默认行为是在Enter上打开文件。有没有办法改变这种行为,以便在Enter上打开文件?到目前为止我找到的唯一解决方法是CTRL + Enter,它在新窗格中打开文件,但在VSCode中有3个窗格限制,这是非常有限的。
如果其他人遇到此问题,则在Mac上的VSCode中从文件资源管理器中打开文件的键盘快捷键是:
CMD +向下
这也适用于Finder。
在版本1.19.2中,在Mac上我可以转到键盘快捷键(菜单栏>代码>首选项>键盘快捷键),搜索“重命名”,然后编辑“renameFile”(“当”值为“explorerViewletVisible && filesExplorerFocus” &&!inputFocus“)将快捷方式更改为”cmd + enter“。
您还可以在keybindings.json中找到以下内容(键盘快捷方式页面上有一个指向它的链接):
{
"key": "cmd+enter",
"command": "renameFile",
"when": "explorerViewletVisible && filesExplorerFocus && !inputFocus"
}
Enter现在在资源管理器中打开突出显示的文件,然后按ctrl + enter将其置于重命名/编辑模式。
-编辑-
升级到1.21.0后,回车键再次开始作为renameFile运行。 cmd + enter仍然可以作为renameFile运行。要修复此问题,请转到菜单栏>代码>首选项>键盘快捷键,然后右键单击有问题的条目并将其删除,或在keybindings.json中的命令开头添加连字符/减号:
{
"key": "enter",
"command": "-renameFile",
"when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !inputFocus"
}
所以我也碰到了这个,但我最终使用的键盘快捷键是映射cmd+enter
重命名并从enter
中删除renameFile。
{
"key": "cmd+enter",
"command": "renameFile",
"when": "explorerViewletVisible && filesExplorerFocus"
},
{
"key": "enter",
"command": "-renameFile",
"when": "explorerViewletVisible && filesExplorerFocus"
}
cmd+down
不能在Mac 10.10.5上使用VSCode 1.10.2。
但是,cmd+enter
对我有用。
或者,如果要设置自己的键绑定以从文件资源管理器中打开文件,请将这些行添加到keybindings.json
:
// open file from File Explorer
{ "key": "enter", "command": "list.select",
"when": "explorerViewletVisible && filesExplorerFocus" },
(当然,您可以将enter
更改为您想要的任何组合键)。
我最终在这里编译了一些解决方案以获得以下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"
}
我试图删除“重命名”的快捷方式,它具有“输入”的键绑定。然后,当我按“Enter”时,它会正确打开文件。
对我来说,我必须做command
0
,然后做一个command
down
这将我带到探险家,然后打开我选择的文件。在Atom中,我只需要打enter
打开文件,我发现这是一个奇怪的行为。 vscode v 1.21.1
在OSX
在偏好中:
代码 - >首选项 - >键盘快捷键
将其添加到您的keybindings.json
{
"key": "ctrl+n",
"command": "workbench.action.files.newFile"
}
在数组中,可能包含或不包含您设置的其他键绑定。保存keybindings.json
然后,当您导航到文件资源管理器中的目录时,可以使用ctrl + n创建新文件
不确定为什么“输入”行为是不同的,我不确定单独的“输入”是在您的系统上的键绑定中设置还是它默认为基于操作系统标准的不同行为...
好消息是,你要找的是CTRL + P或CTRL + O.
CTRL + P让你找到一个文件,CTRL + O应该打开它(你想要的确切行为)
您也可以添加“Enter”作为“workbench.action.files.openFile”命令的可能性,但不确定是否会破坏任何内容。试试吧,或者只是习惯在两个平台上使用CTRL + O!
更多信息:
https://code.visualstudio.com/Docs/customization/keybindings