2101

I am using Visual Studio Code 1.3.1 with the newly introduced tabs.

When I click on files, the first file will open in a tab. If I do not make any changes to this file, the second clicked file will open in the same tab.

How can I avoid this and make Visual Studio Code always open a new tab?

Cornelius Roemer
10.3k5 gold badges62 silver badges120 bronze badges
asked Aug 2, 2016 at 6:43
6
  • 11
    See stackoverflow.com/questions/45945820/… Alt-Enter added this functionality as of v1.19 in December 2017. Commented Dec 15, 2017 at 22:33
  • 47
    if you double click and open the file form left panel, it will not be replaced by other tabs Commented Aug 21, 2018 at 14:50
  • for those who want to open new file in the previous session (in a new tab, when VScode is off): "window.restoreWindows": "preserve", github.com/microsoft/vscode/issues/36964 Commented Feb 15, 2022 at 9:29
  • 1
    Haven't seen it mentioned, but you can also middle-click in the Explorer sidebar and that will open it in normal, non-preview mode Commented Oct 29, 2023 at 19:33
  • Why are there so many duplicate answers to this question? Probably need a clean-up? Commented Apr 29, 2024 at 10:46

36 Answers 36

1
2
3529

When you [single-]click a file in the left sidebar's file browser or open it from the quick open menu (Ctrl-P, type the file name, Enter), Visual Studio Code opens it in what's called "Preview Mode", which allows you to quickly view files.

Preview Mode tabs are not kept open. As soon as you go to open another file from the sidebar, the existing Preview Mode tab (if one exists) is used. You can determine if a tab is in Preview Mode, by looking at its title in the tab bar. If the title is italic, the tab is in preview mode.

To open a file for editing (i.e. don't open in Preview Mode), double-click on the file in the sidebar, or single-click it in the sidebar then double click the title of its Preview Mode tab.

If you want to disable Preview Mode all together, you can do so by setting "workbench.editor.enablePreview": false in your settings file. You can also use the "workbench.editor.enablePreviewFromQuickOpen" option to disable it only from the quick open menu.

Before you can disable Preview Mode, you'll need to open your Settings File.

Pro Tip: You can use the Command Palette(shortcut Ctrl+Shift+P) to open your settings file, just enter "Preferences: Open User Settings"!

Once you've opened your settings file (your settings file should be located on the right), add the "workbench.editor.enablePreview" property, and set its value to false.

You can learn more about Visual Studio Code's "Preview Mode" here.
See also article How to Always Open Files in a New Tab - VSCode

Michael Freidgeim
28.8k17 gold badges164 silver badges181 bronze badges
answered Aug 2, 2016 at 14:22
Sign up to request clarification or add additional context in comments.

8 Comments

can i change double-click to ctrl+click ?
Since I have arrived the second time within a few months at this answer, also note that there is a Workbench > Editor: Show Tabs setting, which, when disabled, looks similar to the preview mode, because you never see a tab appearing except the one you open.
When using ctrl+p to locate a file, you can also use alt+enter or press the right arrow key while the file is highlighted to open it in normal mode (not preview mode)
I submitted a PR to change the default behaviour github.com/microsoft/vscode/pull/115088
It's not only most useless feature, it's also actually quite annoying. If I knew I would have upvoted it in the discussion thread. It's a strange criterion for a backlog candidate. I don't think regular users regularly check GitHub's issues looking for upvoting new features.
|
268

Open setting.json file, and add the following:

"workbench.editor.enablePreview": false
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Aug 1, 2017 at 7:33

2 Comments

Most straight to the point answer. Additionally, you can find settings.json by hitting shift+command+p (command palett) in macOS and entering in "settings.json".
Simple and direct, I like this. I would just specify that you need to choose between workspace's settings.json and the user's settings.json. Probably the user's makes more sense, as it's something you'd want across all projects.
216

If you don't want to disable preview mode you can explicitly tell vscode to keep a specific tab open. As mentioned above a tab heading with italic text is in preview mode.

To get a tab out of preview mode you can either right click on the tab and choose keep open or use the shortcut cmd + k enter that is mapped to the command workbench.action.keepEditor.

Furthermore, double-clicking on a tab also gets it out of preview mode (verified in vscode 1.44.0).

Adrian Mole
52.1k193 gold badges61 silver badges101 bronze badges
answered Jan 4, 2017 at 9:45

1 Comment

For future readers its: CMD+k release key combo and then hit Enter
92

For 2024:

easy as pie, tap preferences (that's command ⌘ + , on Mac),

The secret is "Enable preview"

they added it right there:

enter image description here

The logic is:

Turn OFF (uncheck) for NORMAL behavior.

i.e.:

Turn OFF (uncheck) to avoid the "automatic closing" behavior.

answered Jan 3, 2021 at 16:48

2 Comments

this adds almost nothing on top of this answer from 2017.
It does, as it demonstrates how to change the setting via the UI instead of trawling through a settings file.
51

Use workbench.editor.enablePreview: false to disable Preview mode completely.

Use workbench.editor.enablePreviewFromQuickOpen: false to disable Preview mode for the files open from quick open menu.

answered Sep 29, 2017 at 23:28

Comments

39

Open in new Tab Solution:

  1. Open the command palette by: Cmd + Shift + K
  2. Open settings file by: Preferences: Open Settings (JSON)
  3. Under user setting, enable Tabs by: "workbench.editor.showTabs": true
Gama11
34.6k9 gold badges92 silver badges107 bronze badges
answered Nov 15, 2018 at 0:35

1 Comment

CMD + Shift + P opens the Command Palette now. (CTRL on Win). Ref: code.visualstudio.com/docs/getstarted/…
36

Watch for filenames in italic

Note that, the file name on the tab is formatted in italic if it has been opened in Preview Mode.

Quickly take a file out of Preview Mode

To keep the file always available in VSCode editor (that is, to take it out of Preview Mode into normal mode), you can double-click on the tab. Then, you will notice the name becomes non-italic.

Of course, you can simply double-click to open a file. This will open the file in a new tab, skipping the Preview Mode.

Feature or bug?

I believe Preview Mode is helpful especially when you have limited screen space and need to check many files.

answered Sep 8, 2017 at 3:41

1 Comment

It may also be worth mentioning that you can skip preview mode in the first place by double-clicking the file as you open it.
29

⚡ Actually, VSCode shows you the preview of a file.

You can disable the preview with this:

"workbench.editor.enablePreview": false,

⬇️ Basically just add these two settings and you're good to go.

VSCode tip

Samuel RIGAUD
1,6981 gold badge19 silver badges28 bronze badges
answered May 18, 2018 at 12:27

1 Comment

26

For anyone who don't want to disabled Preview Mode.

As I read whole of comments and I found what I preferred that is the shortcut key to pin the opened file from Quick Open/Ctrl+P or that's mean to keep the opened file to the editor, and yes also don't need to switch your hand to the mouse to double-click on files list.

Thanks to @jontem and @MattLBeck.

Call save command with Ctrl+S (+S on Mac) is the easiest way to reach what I preferred.

And if you found out you do this to keep opened file to editor quite frequently, yes I preferred you should setting the option "workbench.editor.enablePreview": false or "workbench.editor.enablePreviewFromQuickOpen": false as others mentioned before.

Nimantha
6,5156 gold badges32 silver badges78 bronze badges
answered May 18, 2018 at 10:40

Comments

22

Menu FilePreferencesUser Settings: add this line

"workbench.editor.enablePreviewFromQuickOpen": false

leanne
8,8991 gold badge57 silver badges82 bronze badges
answered Apr 26, 2018 at 13:50

1 Comment

what does this add on top of this answer from 2017?
19

This is not a new answer. It is just showing how to do it via UI. Open settings via File => Preference => Settings. The most upvoted answer is the correct choice.

Then in search field type Preview.

After that select Workbench and look for Enable preview options.

Uncheck the boxes.

enter image description here

2240
1,7303 gold badges17 silver badges36 bronze badges
answered Jul 17, 2020 at 12:30

Comments

18

If you want to open a file permanently from "Go To File..." (+P), press "right arrow" instead of return.

This also keeps the Go To File... search bar open so you can quickly open multiple files.

Nimantha
6,5156 gold badges32 silver badges78 bronze badges
answered Jan 27, 2020 at 16:38

3 Comments

Yep. Pressing "right arrow" to open in a new tab works on Windows too.
Perfect - THIS should have been the accepted answer, as it does not 'fix' the problem by disabling a useful feature, but instead answers the question by showing how Ctrl-P to open files should be used! The fact it keeps the Go To File open as well is an excellent bonus
This is no longer working, has this feature been removed? Can anyone confirm if it still works?
14

From settings you can find edit settings.json
You need to search by Preview:

Image of this section

Add the below code there:

"workbench.editor.enablePreview": false 

Full code:

{
 "editor.codeActionsOnSave": {
 
 },
 
 "workbench.editor.enablePreview": false,
}
Nimantha
6,5156 gold badges32 silver badges78 bronze badges
answered Mar 13, 2022 at 6:15

Comments

14

1. Double-click your files instead of single-clicking

  • Instead of single clicking on your files, (like I do in the previous GIF) double-click. This will tell VS Code that you want the file to stay open when you switch to a new file:

    enter image description here

2. Double-click the tab you want to keep open

  • This works if the tab you are working with is in "Preview Mode" (italicized) and you want it to stay open when you open another file:

    enter image description here

3. Right click your tab and select "Keep Open"

  • This one's self-explanatory. Simply right-click on the Preview Mode tab on the tab at the top of your screen (while it's italicized) and click on "Keep Open" once the context menu pops up:

    enter image description here

When you single-click a file in the left sidebar's file browser or open it from the quick open menu (Ctrl+P, type the file name, Enter), Visual Studio Code opens it in what's called "Preview Mode", which allows you to quickly view files.

It's a feature, not a bug.

  • Very often while programming you will only need to open a file for a small window of time, to "preview" its contents.

For more info

Nimantha
6,5156 gold badges32 silver badges78 bronze badges
answered Sep 17, 2022 at 13:55

Comments

13

You can do it via GUI

enter image description here

Search for preview

enter image description here

uncheck the options Enable Preview and Enable Preview from Quick Open

answered Dec 27, 2018 at 5:52

Comments

11

Essentially, there are three settings that one has to update (Preference>> settings):

  • workbench.editor.enablePreview: set this to globally enable or disable preview editors

  • workbench.editor.enablePreviewFromQuickOpen: set this to enable or disable preview editors when opened from Quick Open

  • workbench.editor.showTabs: finally one will need to set this
    otherwise, there will be no tabs displayed and you will just be
    wondering why setting/unsetting the above two did not work

answered Mar 7, 2019 at 6:16

Comments

10

Enabling using GUI

Go to Code -> Preferences -> Settings -> User -> Window -> New Window

Here Open Files In New Window under drop down list select "on" that's it.

My VS Code version 1.38.1

Nimantha
6,5156 gold badges32 silver badges78 bronze badges
answered Oct 3, 2019 at 5:25

2 Comments

I was having an issue where "Go to definition..." was continually opening in same file window (was frustrating as would have to re-find my starting point). This seemed to fix things for me mostly (initial "Go to definition..." now opens in new file window).
This setting is as far as I'm aware about if new windows should be opened, not the permanence of tabs.
9

As hktang indicates:

one Click opens the file in preview mode (header text in italics)

Double click the same file, it goes out of preview-mode (header text changes from italic to normal font)

I think this is a "compromise" feature allowing users, to "navigate" both worlds; preview and none-preview.

  • All you do is click the file to open it in the right panel.
  • Then immediately double click it to keep it there.
  • Or - just treble click. File opens in none preview mode.
Nimantha
6,5156 gold badges32 silver badges78 bronze badges
answered Jan 4, 2019 at 11:31

Comments

7

You need to edit settings.json file, which is located at:

Windows %APPDATA%\Code\User\settings.json
macOS $HOME/Library/Application Support/Code/User/settings.json
Linux $HOME/.config/Code/User/settings.json
{
 "workbench.editor.showTabs": true,
 "workbench.editor.enablePreview": false
}
Audwin Oyong
2,5273 gold badges21 silver badges37 bronze badges
answered Apr 5, 2020 at 18:14

Comments

5
  • Go to File > Preferences > Settings
  • Search for workbench.editor.enablePreviewFromQuickOpen
  • Set it to false or uncheck it.
answered May 25, 2021 at 12:20

Comments

4

Actually, VSCode shows you the preview of a file when you open it. If you want to open files in a new tab, just disable the preview with this setting (paste this in the settings.json file).

"workbench.editor.enablePreview": false, 

— you can take it one step further and use this setting

"workbench.startupEditor": "newUntitledFile",

— It will open your VSCode editor with a blank new untitled file to quickly get started.

answered May 5, 2020 at 10:47

Comments

4

For those who using Windows OS:

  • Press Ctrl + Shift + P
  • Select Preferences: Open Settings (JSON) from the list
  • Select all and Paste this { "workbench.editor.enablePreview": false }

That's it now it will open in a new tab instead of replacing on the existing one.

For reference look at the screenshot below:

enter image description here

answered Jul 22, 2020 at 13:37

Comments

4

To open another file in a new tab keeping the current file open,

  • First double click (left click) the current file
  • Then click (single click) the new file

In this way, the new file will be opened in another tab

#OR

You can drag the new file from VS Code project explorer and drop it beside opened tab, exactly where the new tab will be opened

Nimantha
6,5156 gold badges32 silver badges78 bronze badges
answered Jul 23, 2021 at 12:27

Comments

4

Follow the instructions:

For Version: 1.85.1 follow the instruction

VS Code Version:

  • 1.85.1
  • 1.95.1
  • 1.96.2
Nimantha
6,5156 gold badges32 silver badges78 bronze badges
answered Feb 15, 2024 at 15:56

1 Comment

Could you add some text on each of the steps? The answer is currently only image based - it's fine as a supplement, but it's important to have the steps written as text within the answer, e.g. - "1. Ctrl+,..."
3

Put that in setting.json.

"workbench.editor.showTabs": true,
Nimantha
6,5156 gold badges32 silver badges78 bronze badges
answered Jul 25, 2023 at 16:48

1 Comment

For me worked "window.restoreWindows" then selected "Preserve". Now if the editor is closed and I double click a file ( to open it ), the editor will open all the previous files that were left opened in the last use of the editor + the new file I've just doubled clicked on.
3

Simple way is whenever you open new file it is in preview mode so simply press the CTRL + K and then press ENTER then you done with preview mode. Now this file will remain always open until you closed it that's what you need to do.

Nimantha
6,5156 gold badges32 silver badges78 bronze badges
answered Aug 2, 2020 at 6:08

Comments

2

One simple solution is, instead of making changes in settings of VS Code, whenever you open a file through a reference, you will see that the file is in preview mode (the name of file is in italic) and in the sidebar you will see that same preview file in focus just double tap it and it will be pinned on the tab, so that it won't get replaced by another file in preview mode.

Nimantha
6,5156 gold badges32 silver badges78 bronze badges
answered Aug 6, 2019 at 6:59

Comments

1

In my case, I also had to set workbench.editor.showTabs property to true (in addition to workbench.editor.enablePreview)

I'm not sure how it got changed to false. Maybe, I've accidentally set it to false using some shortcut.

answered Oct 22, 2018 at 19:39

Comments

1

This is so confusing. All developers I asked didn't appreciate this default behavior.

I use cmd + P to open project files.

Misha Akopov
13.1k27 gold badges72 silver badges87 bronze badges
answered Aug 2, 2018 at 13:59

Comments

1

Settings -> Workbench -> Editor Management -> Enable Preview

answered Jan 26, 2020 at 13:40

Comments

1
2

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.