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?
36 Answers 36
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
9 Comments
double-click to ctrl+click ?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.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)Open the settings.json file, and add the following:
"workbench.editor.enablePreview": false
Screenshot of this setting in the IDE
3 Comments
settings.json by hitting shift+command+p (command palett) in macOS and entering in "settings.json".If you don't want to disable preview mode, you can explicitly tell Visual Studio Code 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 Visual Studio Code 1.44.0).
2 Comments
CMD+k release key combo and then hit EnterFor 2024:
It is easy as pie. Tap preferences (that's command ⌘ + , on Mac).
The secret is "Enable preview"
They added it right there:
The logic is:
Turn OFF (uncheck) for NORMAL behavior.
I.e.:
Turn OFF (uncheck) to avoid the "automatic closing" behavior.
2 Comments
Use workbench.editor.enablePreview: false to disable Preview mode completely.
Use workbench.editor.enablePreviewFromQuickOpen: false to disable Preview mode for the files open from the quick open menu.
Comments
Open in a new tab solution:
- Open the Command Palette by: Cmd + Shift + K
- Open the settings file by: Preferences: Open Settings (JSON)
- Under user settings, enable tabs by:
"workbench.editor.showTabs": true
3 Comments
Watch for filenames in italic
Note that, the file name on the tab is formatted in italics if it has been opened in Preview Mode.
Quickly take a file out of Preview Mode
To keep the file always available in the Visual Studio Code 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 screenspace and need to check many files.
1 Comment
⚡ Actually, Visual Studio Code 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:
3 Comments
For anyone who don't want to disable Preview Mode.
As I read the 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 meant 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 the files list.
Thanks to @jontem and @MattLBeck.
Call the 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 the opened file to edit quite frequently, yes, I preferred you should set the option "workbench.editor.enablePreview": false or "workbench.editor.enablePreviewFromQuickOpen": false as others mentioned before.
Comments
Menu File → Preferences → User Settings: add this line
"workbench.editor.enablePreviewFromQuickOpen": false
1 Comment
This is not a new answer. It is just showing how to do it via the UI.
Open settings via menu File → Preferences → Settings. The most upvoted answer is the correct choice.
Then in the search field, type Preview.
After that, select Workbench and look for the Enable Preview options.
Uncheck the boxes.
Comments
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.
4 Comments
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,
}
Comments
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 Visual Studio 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.
Comments
You can do it via the GUI:
Search for preview:
Uncheck the options Enable Preview and Enable Preview from Quick Open.
1 Comment
Essentially, there are three settings that one has to update (menu File → Preferences → 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
Comments
Enabling using the GUI:
Go to Code → Preferences → Settings → User → Window → New Window
Here Open Files In New Window, and under the drop down list, select "on". That's it.
My Visual Studio Code version is 1.38.1.
2 Comments
As hktang indicates:
One click opens the file in preview mode (header text in italics).
Double-click the same file, and 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 non-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 triple-click. The file opens in non-preview mode.
Comments
You need to edit the 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
Content:
{
"workbench.editor.showTabs": true,
"workbench.editor.enablePreview": false
}
Comments
- Go to menu File → Preferences → Settings
- Search for workbench.editor.enablePreviewFromQuickOpen
- Set it to false or uncheck it.
Comments
Actually, Visual Studio Code 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 Visual Studio Code editor with a blank new untitled file to quickly get started.
Comments
For those who are using the 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 the existing one.
For reference, look at the screenshot below:
Comments
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 the Visual Studio Code project explorer and drop it beside the opened tab, exactly where the new tab will be opened
Comments
Follow the instructions:
For version: 1.85.1 follow the instruction
Visual Studio Code versions:
- 1.85.1
- 1.95.1
- 1.96.2
1 Comment
Ctrl+,..."A simple way is whenever you open new file, it is in preview mode, so simply press Ctrl + K, and then press ENTER. Then you are done with preview mode.
Now this file will remain always open until you close it. That's what you need to do.
Comments
Put that in settings.json :
"workbench.editor.showTabs": true,
1 Comment
One simple solution is, instead of making changes in settings of Visual Studio 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). 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.
Comments
This is so confusing. All developers I asked didn't appreciate this default behavior.
I use cmd + P to open project files.
1 Comment
Shift + Enter did the trick for me.
2 Comments
In my case, I also had to set the 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 keyboard shortcut.
Comments
Explore related questions
See similar questions with these tags.
"window.restoreWindows": "preserve",github.com/microsoft/vscode/issues/36964