简体   繁体   中英

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. However, I've only figured out how to open a selected file in a new editor pane ( Ctrl+Enter ).

Is there a shortcut to open it in the same pane? Can I change the behavior of the Ctrl+Enter shortcut? A pointer to the right docs would also be helpful.

This closest action is filesExplorer.openFilePreserveFocus , which is bound by default to 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!

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.

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).

The filesExplorer.openFilePreserveFocus command does what you want with the limitation that it keeps the focus on the explorer sidebar. To move focus to the opened window you can utilize the fact that workbench.view.explorer toggles focus between editor and 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"
  },

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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