129

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
jligeza
  • 4,544
  • 6
  • 23
  • 31
  • 2
    Possible duplicate of [How to config vscode to open files always in a new tab?](https://stackoverflow.com/questions/38713405/how-to-config-vscode-to-open-files-always-in-a-new-tab) – jamesdlin Jan 22 '18 at 04:59

6 Answers6

276

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 the tab will be in italic if it's in preview mode, just like the below screenshot.

To open a file for editing (i.e. don't open in Preview Mode), double-click on the file in the sidebar.

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 the quick open menu, uncheck the box for workbench.editor.enablePreviewFromQuickOpen.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Keshan Nageswaran
  • 8,060
  • 3
  • 28
  • 45
  • 15
    If you want to keep the standard preview behaviour, you can open a file in preview mode using `ctrl+p` and then open it fully for editing using `ctrl+k enter`. This turns the preview tab into a fully independent tab as you'd get if you opened the file by double-clicking it in the explorer. – alphaloop Jan 10 '18 at 09:58
  • 3
    "double click on the file in sidebar" also works for tab titile bar, if tab title bar is italic then double click on it removes preview mode – kewlashu Apr 28 '18 at 06:31
28

TL;DR for Mac users

Step 1: Press +,

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

Search for Preview and disable Workbench › Editor: Enable Preview

Mohammad Zaid Pathan
  • 16,304
  • 7
  • 99
  • 130
6

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

"workbench.editor.enablePreview": false

It is the right answer.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
2

Instead of changing a setting, a simpler option is to drag the file from the sidebar on to the tabs bar. It opens in a new tab.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dheerendra Kulkarni
  • 2,728
  • 1
  • 16
  • 18
1

Go to menu FilePreferencesSettings → search for "settings.json", and at the last line before }, add a comma to the last option and paste:

"workbench.editor.enablePreview": false

For example:

{
    "editor.fontFamily": "'Consolas', 'monospace', 'Times New Roman'",
    "terminal.integrated.fontFamily": "monospace",
    "editor.fontSize": 13,
    "workbench.iconTheme": "vscode-icons",
    "workbench.editor.enablePreview": false
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0

In the quick open menu, a file can be opened in the background by pressing the right arrow key. The current tab, with the quick open menu remains in the foreground, and the same process can be repeated to open multiple files.

VSCode doc can be found here.

sid
  • 1