CharType
CharType

Reputation: 420

How to open files in new tabs in Visual Studio Code

I recently started using Visual Studio Code and I would like to know, is a way to open files in a new tab? Currently whenever I open a new file the files I currently have open disappear. I say new tab, but any option that will let me open a new file in the same window as the old one works.

I have tried disabling Preview Mode through the workbench settings as shown in this answer: How to config vscode to open files always in a new tab?. However, when I choose Open or Open Recent the new file still replaces my old file.

Thanks.

Upvotes: 12

Views: 15456

Answers (6)

VonC
VonC

Reputation: 1324248

Starting with VSCode 1.52 (Nov. 2020), you should not have any more issue: all files will open in new tabs, even in preview mode.

Better handling of preview editors:

Preview editors are now better handled with numerous improvements based on feedback and making this feature work more consistent.

The setting workbench.editor.enablePreviewFromQuickOpen is now disabled by default so that editors opening from quick open will not appear in preview mode anymore.

When you start a navigation (e.g. go to definition), the editor you start from will move out of preview mode to keep it open while the new editor will be in preview mode until you navigate further.

Go to definition -- https://media.githubusercontent.com/media/microsoft/vscode-docs/vnext/release-notes/images/1_52/goto-definition.gif

We changed all of our custom trees (the ones used from extensions or Git changes view for example) to work more consistently like our built-in trees (like the explorer).
This means, the following interactions now apply to all of them:

  • double-click or mouse-middle-click to open non-preview
  • Enter to open non-preview (Space to open in preview-mode)

Note: if you are the author of an extension that is leveraging our custom tree API, you can benefit from this change as well.
Make sure to use vscode.open or vscode.diff commands for the TreeItem.command and you are in!

A new menu item in the editor overflow menu allows to quickly turn off preview editors altogether:

Keep Open -- https://media.githubusercontent.com/media/microsoft/vscode-docs/vnext/release-notes/images/1_52/keep-open.png

Upvotes: 2

iun1x
iun1x

Reputation: 1093

This is likely due to Visual Studio Code opening file in what's called "Preview Mode", which allows you to quickly view files, ideally if a tab is in Preview Mode then its title in the tab bar, will be italic.

To disable Preview Mode set "workbench.editor.enablePreview": false in your settings file or use the "workbench.editor.enablePreviewFromQuickOpen" option to disable it only from the quick open menu.

Alternatively, use command palette CTL+Shift+P (to get all settings) VScode settings then in User => Workbench => Editor Management you can uncheck Enable Preview and Enable Preview from Quick Open to get the same results described above

Upvotes: 2

Dev-is-me_jn
Dev-is-me_jn

Reputation: 51

For 1.21.1 version.

In user settings =>

"workbench.editor.enablePreview": false, "workbench.editor.enablePreviewFromQuickOpen"

the best way i found.

Upvotes: 5

CharType
CharType

Reputation: 420

Thanks everyone. Double clicking and dragging was useful, but it still didn't solve my problem when opening files from different projects with the "Open File" menu command. I found that Multi-root Workspaces is what I was looking for. https://code.visualstudio.com/docs/editor/multi-root-workspaces

Upvotes: 0

Akil Makda
Akil Makda

Reputation: 431

Once you have to open your settings file, add the "workbench.editor.enablePreview" property and set value to false.

Upvotes: 13

Saurabh Ghewari
Saurabh Ghewari

Reputation: 709

  1. You need to double click on the name of the file. Also, it needs to be done swiftly elsewhere you will be opening in the same tab.
  2. You can drag and drop file near to the opened tab and the file will open in new tab.

Upvotes: 2

Related Questions