简体   繁体   English

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

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

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.在 Windows 上使用 VSCode 时,我可以导航文件资源管理器并在焦点文件上按Enter ,该文件将在编辑器中打开。 On my Mac, however, when I do this, VSCode will open the rename input as follows:然而,在我的 Mac 上,当我这样做时,VSCode 将打开重命名输入,如下所示:

在此处输入图片说明

I'm not sure why it does this.我不确定它为什么这样做。 Even in other text editors (eg Atom), the default behavior is to open the file on Enter .即使在其他文本编辑器(例如 Atom)中,默认行为也是按Enter打开文件。 Is there any way to change this behavior so that the file opens on Enter ?有没有办法改变这种行为,以便文件在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.到目前为止,我发现的唯一解决方法是CTRL + Enter ,它会在新窗格中打开文件,但在 VSCode 中限制为 3 个窗格,这是非常有限的。

If anyone else comes across this problem, the keyboard shortcut to open a file from the file explorer in VSCode on a Mac is:如果其他人遇到此问题,在 Mac 上的 VSCode 中从文件资源管理器打开文件的键盘快捷键是:

CMD + Down CMD +向下

This also works in Finder.这也适用于 Finder。

I ended up compiling a few solutions here together to get the following keybinding.json editions (Open via Code > Preferences > Keyboard Shortcuts > keybindings.json ):我最终在这里编译了一些解决方案以获得以下keybinding.json版本(通过Code > Preferences > Keyboard Shortcuts > keybindings.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"
  }

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."在 1.19.2 版本中,在 Mac 上,我可以转到键盘快捷键(菜单栏 > 代码 > 首选项 > 键盘快捷键),搜索“重命名”,然后编辑“重命名文件”(“何时”值为“explorerViewletVisible && filesExplorerFocus” && !inputFocus") 将快捷方式更改为“cmd+enter”。

You can also past the following in your keybindings.json (there's a link to it on the keyboard shortcuts page):您还可以在 keybindings.json 中粘贴以下内容(在键盘快捷键页面上有一个链接):

{
  "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. Enter 现在在资源管理器中打开突出显示的文件,ctrl+enter 将其置于重命名/编辑模式。


–Edit– -编辑-

After I upgraded to 1.21.0 the enter key started functioning as renameFile again.升级到 1.21.0 后,回车键再次开始用作 renameFile。 cmd+enter still functioned as renameFile as well. cmd+enter 仍然起到 renameFile 的作用。 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:要解决此问题,请转到菜单栏 > 代码 > 首选项 > 键盘快捷键,然后右键单击违规条目并将其删除,或者在 keybindings.json 中的命令开头添加连字符/减号:

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

在我的 Mac 上,只需按空格键即可为我打开文件。

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 .所以我也遇到了这个问题,但我结束使用的键盘快捷键是映射cmd+enter以重命名并从enter删除 renameFile 。

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

cmd+down does NOT work for me using VSCode 1.10.2 on Mac 10.10.5. cmd+down在 Mac 10.10.5 上使用 VSCode 1.10.2 对我不起作用。

However, cmd+enter does work for me.但是, cmd+enter对我有用。

Or if you want to set your own keybinding to open a file from File Explorer, add these lines to your keybindings.json :或者,如果您想设置自己的键绑定以从文件资源管理器打开文件,请将这些行添加到您的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). (当然,您可以将enter更改为您想要的任何组合键)。

I tried to remove the shortcut of "Rename", which has the Keybinding of "Enter".我试图删除具有“Enter”键绑定的“重命名”快捷方式。 Then it opens the file properly when I press "Enter".然后当我按“Enter”时它会正确打开文件。

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.对我来说,我必须先执行command 0 ,然后再执行down command down这会将我带到资源管理器,然后打开我选择的文件。 In Atom, I just had to hit enter to open the file, I find this to be a strange behavior.在 Atom 中,我只需按enter键即可打开文件,我发现这是一种奇怪的行为。 vscode v 1.21.1 on OSX OSX上的vscode v 1.21.1

  • SPACE : open but keep focus on Explorer ( filesExplorer.openFilePreserveFocus command) SPACE :打开但关注资源管理器( filesExplorer.openFilePreserveFocus命令)
  • CMD+Down : open and focus the opened file ( explorer.openAndPassFocus command) CMD+Down :打开并聚焦打开的文件( explorer.openAndPassFocus命令)

You can change them in "Code - Preferences - Keyboard Shortcuts":您可以在“代码 - 首选项 - 键盘快捷键”中更改它们: 键盘快捷键(代码 - 首选项 - 键盘快捷键)

In preferences:在偏好中:

Code -> Preferences -> Keyboard Shortcuts代码 -> 首选项 -> 键盘快捷键

Add this to your keybindings.json将此添加到您的 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保存 keybindings.json

Then when you navigate to a directory in the file explorer, you can create a new file with ctrl+n然后当您导航到文件资源管理器中的目录时,您可以使用 ctrl+n 创建一个新文件

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 或 CTRL+O

CTRL+P let's you find a file, and CTRL+O should open it (the exact behavior you'd like) CTRL+P 让你找到一个文件,CTRL+O 应该打开它(你想要的确切行为)

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.您也可以为“workbench.action.files.openFile”命令添加“Enter”作为一种可能性,但不确定这样做是否会破坏任何内容。 Try it, or just get used to using CTRL+O on both platforms!试试吧,或者只是习惯在两个平台上使用 CTRL+O!

More info:更多信息:

https://code.visualstudio.com/Docs/customization/keybindingshttps://code.visualstudio.com/Docs/customization/keybindings

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM