简体   繁体   English

如何在同一 window 中从 VSCode 文件资源管理器打开文件

[英]How to open file from VSCode file explorer in same window

Using cmd+shift+e I can highlight the file explorer tab and then use vim keybindings to select a given file.使用cmd+shift+e我可以突出显示文件资源管理器选项卡,然后使用 vim 键绑定到 select 给定文件。 However, I've only figured out how to open a selected file in a new editor pane ( Ctrl+Enter ).但是,我只知道如何在新的编辑器窗格( Ctrl+Enter )中打开选定的文件。

Is there a shortcut to open it in the same pane?是否有在同一窗格中打开它的快捷方式? Can I change the behavior of the Ctrl+Enter shortcut?我可以更改Ctrl+Enter快捷方式的行为吗? A pointer to the right docs would also be helpful.指向正确文档的指针也会有所帮助。

This closest action is filesExplorer.openFilePreserveFocus , which is bound by default to Space .这个最接近的操作是filesExplorer.openFilePreserveFocus ,它默认绑定到Space

This will open the file currently selected in a new tab, but it won't move your cursor to it.这将打开当前在新选项卡中选择的文件,但不会将光标移至该文件。

You can use the cmd+shift+e keybinding to get back to your editor, though!不过,您可以使用cmd+shift+e键绑定返回到您的编辑器!

From the docs文档

The settings window.openFoldersInNewWindow and window.openFilesInNewWindow are provided to configure opening new windows or reusing the last active window for files or folders and possible values are default, on and off.设置window.openFoldersInNewWindowwindow.openFilesInNewWindow用于配置打开新窗口或重新使用文件或文件夹的最后一个活动窗口,可能的值是默认值、打开和关闭。

If configured to be default, we will make the best guess about reusing a window or not based on the context from where the open request was made.如果配置为默认值,我们将根据发出打开请求的上下文对是否重用窗口做出最佳猜测。 Flip this to on or off to always behave the same.将此打开或关闭以始终保持相同的行为。 For example, if you feel that picking a file or folder from the File menu should always open into a new window, set this to on.例如,如果您觉得从“文件”菜单中选择一个文件或文件夹应该总是在新窗口中打开,请将其设置为打开。

Note: There can still be cases where this setting is ignored (for example, when using the -new-window or -reuse-window command-line option).注意:仍有可能忽略此设置(例如,使用 -new-window 或 -reuse-window 命令行选项时)。

The filesExplorer.openFilePreserveFocus command does what you want with the limitation that it keeps the focus on the explorer sidebar. filesExplorer.openFilePreserveFocus命令可以满足您的要求,但它会将焦点保持在资源管理器侧边栏上。 To move focus to the opened window you can utilize the fact that workbench.view.explorer toggles focus between editor and explorer.要将焦点移至打开的 window,您可以利用workbench.view.explorer在编辑器和资源管理器之间切换焦点的事实。 Together with a extension such as multi-command that enables running multiple commands the desired behaviour can be achieved:与允许运行多个命令的扩展(例如多命令)一起,可以实现所需的行为:

  {
      "key": "enter",
      "command": "extension.multiCommand.execute",
      "args": {
        "sequence": [
          "filesExplorer.openFilePreserveFocus",
          "workbench.view.explorer",
        ],
      },
      "when": "explorerViewletFocus && explorerViewletVisible && !inputFocus"
  },

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

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