How to open file in new tab in Visual Studio Code?

2019-01-16 13:38发布

问题:

How do I open a new file using ctrl+p, so it doesn't override the current file, but rather use a new tab?

Also, would it be possible to focus the searched file instead of opening it, if it was already opened on a tab, to avoid duplicates?

回答1:

When a single click to a file is made in the sidebar, Visual Studio Code opens it in Preview Mode, which allows you to quickly view files.

Behavior of Preview Mode

  • The tabs in the Preview Mode are not kept open.
  • As soon as you open another file from the sidebar, it overrides the existing file if it's in preview mode.
  • The title of tab will be in italic if it's in preview mode Just like the below screenshot.

Important!

If you want to edit a file, don't open in Preview Mode, double-click on the file in the sidebar instead.

If the file is already open in Preview mode, then to convert it to edit mode:

  • double click on its italic file name in the title bar, OR
  • press Ctrl-K Enter

Steps to Disable Preview Mode

Criteria:

If you want to disable Preview Mode all together, that is:

  • accessing file through side-menu.
  • opening quick open menu using Ctrl + P.

Solution:

  • Open the Command Palette using the shortcut Ctrl+Shift+P.
  • Type Preferences: Open User Settings, this will open the Settings editor. Search for workbench.editor.enablePreview, and uncheck the checkbox. (changes are autosaved and indicated with a blue left border)

Additional:

  • If you only want to disable preview mode in quick open menu, uncheck the box for workbench.editor.enablePreviewFromQuickOpen.


回答2:

TL;DR for Mac users

Step 1: Press +,

Step 2: Search for Preview and disable Workbench › Editor: Enable Preview



回答3:

for both to keep a file tab open when you first click and after use go to definition,

"workbench.editor.enablePreview": false

is the right answer.



回答4:

One more simpler option instead of changing setting is drag the file from sidebar on to the tabs bar it opens in new tab.