Visual Studio Code replaces my opened tabs when opening file from Finder - visual-studio-code

I'm using Visual Studio Code v1.21.1 on macOS Sierra.
I have a workspace with about 9 or 10 tabs with the files that I used all the time. But if I want to open a new file associated with VSC by double clicking it on Finder, instead of just opening it in my current instance as a new tab, it closes the instance (with all the other 10 files) and opens alone.
I can't find any setting that changes this behavior to what other editors do, and which is basically opening a file from the operating system's Finder in a new tab, whilst keeping all my other stuff opened.

This happens because of preview mode in VsCode which opens the file as a preview (the file opened as a preview will have italic file name), you have to pin the preview by editing or douple clicking the tab.
you can also disable the preview mode from the setting screen under
workbench.editor.enablePreview
you can find detailed explanation here https://www.brcline.com/blog/force-vscode-open-files-new-tab

Related

How to get editors restored when reopening a closed VS Code window?

I am using VSCode on my Mac (Latest version) and when I hit the "Red X" on the top left of VSCode it closes my entire workspace and open editors. I want it to just close the window out of my view but keep everything open when I re-open the app (it is still running as it still has the white dot below).. I am getting the welcome page everytime I just "close window" and re-open.
Now if I were to two click and hit Quit, then yes, I'd expect my workspace and editors to all close and get the startup menu on re-opening.
I have tried searching in the settings and cannot find anything.
GUI Red X - VSCODE
Example. When playing music on iTunes and press the "RedX" on the GUI music keeps playing and everything opens as it was when it was closed. Thatis what I am trying to acheive on VSCode. Keep my "sandbox" and open files as is when pressing it..
To VS Code, I'm pretty sure that red x button and quit are the same thing (although it may be possible for it to treat them differently). Ie. I'm not aware of a way that you can get different behaviour for the red x button and the application quit action.
As for choosing whether the previous workspace should be reopened automatically, you can use the window.restoreWindows setting.
Controls how windows are being reopened after starting for the first time. This setting has no effect when the application is already running.
The values to choose from and their descriptions at the time of this writing are:
value
description
"all"(default value)
Reopen all windows unless a folder, workspace or file is opened (e.g. from the command line).
"folders"
Reopen all windows that had folders or workspaces opened unless a folder, workspace or file is opened (e.g. from the command line).
"none"
Never reopen a window. Unless a folder or workspace is opened (e.g. from the command line), an empty window will appear.
"one"
Reopen the last active window unless a folder, workspace or file is opened (e.g. from the command line).
"preserve"
Always reopen all windows. If a folder or workspace is opened (e.g. from the command line) it opens as a new window unless it was opened before. If files are opened they will open in one of the restored windows.
If you want open editors to be remembered and the previous workspace to be reopened automatically when you reopen VS Code,
You may also want to set something for the workbench.startupEditor setting, such as:
"workbench.startupEditor": "welcomePage", // or "none" or "newUntitledFile"
Also, loosely related is the "workbench.editor.restoreViewState setting, but the default value is true, so you only need to touch it if you don't want view state info like scroll position to be resotred on reopening closed editors.

Which setting is responsible for making unmodified files not persist as tabs?

If you open a file in VSCode, like so:
Previous VSCode versions, if the file is unmodified, you can open a new file and the tab will be replaced with the new file opened. You needed to save the file to persist the tab. Now all files are opened as new tabs for me. Is there a setting that is responsible for this behavior?
It depends on how you are opening the files. If you are clicking on them from the Explorer, then Workbench > Editor: Enable Preview will control whether those files open in preview or not.
If you are opening them from the QuickOpen panel, then see
The workbench.editor.enablePreviewFromQuickOpen setting is now
disabled by default, so that editors opened from Quick Open will no
longer appear in preview mode.
from the v1.52 Release notes.
So enable workbench.editor.enablePreviewFromQuickOpen so files opened from Quick Open do so in Preview Mode.

Is VS Code supposed to override an existing tab in the nav header? [duplicate]

This question already has answers here:
Open files always in a new tab
(30 answers)
Closed 4 years ago.
In Visual Studio Code supposed to replace/override an existing file tab? When I click package.json with nothing on the editor, it opens package.json
. When I click on README.md it replaced the package.json file with the README. See GIF link below for a visual picture.
Note that these happen after I click the file
Yes, that's a feature called Preview Mode. It provides a way to quickly review files without collapsing your editor with open files. You can tell the file is in preview mode by the italics on the tab.
You can pin the file by double-clicking on the tab (italics go away) or disable the feature altogether:
workbench.editor.enablePreview to globally enable or disable preview editors
workbench.editor.enablePreviewFromQuickOpen to enable or disable preview editors when opened from Quick Open

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.
Once you have to open your settings file, add the "workbench.editor.enablePreview" property and set value to false.
For 1.21.1 version.
In user settings =>
"workbench.editor.enablePreview": false,
"workbench.editor.enablePreviewFromQuickOpen"
the best way i found.
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.
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:
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.
You can drag and drop file near to the opened tab and the file will open in new tab.
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
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

Visual Studio code always opens the wrong file for me

I have a very weird problem with Visual studio code (Version 1.20.1 (1.20.1)).
In full screen mode on a Mac. (High Sierra) when I double click a file. it always opens the file above it. Meaning that it opens the wrong file (not the one which I double clicked).
Please have a look at this video which I recorded.
https://youtu.be/VG8-AnEpZjY
The video starts with me double click on the file "Tables.scala" but the editor opens the file "ScanFromCassandra" which is above it.
Then I double click Models.scala and it opens the file correctly.
Then I double click Config.scala but the editor opens CommonFlow.scala
This is very very annoying. I don't know if anyone else is facing this issue or not.
Edit:: If I switch off the "open editors" window, then the issue disappears. but I like the "open editors" window. I think the open editors window causes some kind of "jumping" in vscode making it open wrong files.
Actually I figured out the answer after using the editor for some time.
in VSCode when trying to open files in the "explorer" we have to single click on the file name. not double click.
If I single click on the file name it works perfectly.
The problem comes when I double click but that's not required. a single click on the file name to open it works smoothly.