re-open vscode without last workspace or last files - visual-studio-code

I wish set VSCode to be launched clean, no last workspace or last files opened..
is this possible?
I use it as unity3d debugger and annoying me all the times that opens a previous workspace (no workspaces saved)
thanks in advance

Besides my comment above, also see open a new window, v1.22 released today if you prefer to open via a command line.
Controls if a new empty window should open when starting a second
instance without arguments or if the last running instance should get
focus. // - on: open a new empty window // - off: the last active
running instance will get focus // Note that there can still be
cases where this setting is ignored (e.g. when using the -new-window
or -reuse-window command line option).
"window.openWithoutArgumentsInNewWindow": "on"
But the setting
"window.restoreWindows": "none"
should also work for opening in other ways (but seems to require a few restarts - perhaps it has been fixed as of 1.22?).

According to the VSCode command line documentation, you can use -n or --new-window flag to open new session without any old files.
I just checked and it works.
The full command to run VSCode is (on my PC):
"C:\Program Files (x86)\Microsoft VS Code\Code.exe" -n
or just
code -n
Tip: You can change the shortcut for VSCode to include the -n flag so it opens new session always.

None of the other solutions were working for me.
Recently hit this issue where I tried to do a find and replace with 15000 files and vscode crashed while trying to save all those files. I closed the window and re-opened but it kept trying to re-open those 15000 files and would crash again.
I was able to fix this by deleting the corresponding workspace folder (search by folder name) in
/Users/{username}/Library/Application Support/Code/User/workspaceStorage
Then when you reopen that folder nothing is saved or open.

Related

Visual Studio Code terminal displaying "sh-3.2$" every time I "Open in Integrated Terminal" instead of the working directory name (Mac OS)

Earlier today I was having an issue where when I would go to open a new terminal or open a file or folder in Integrated Terminal the terminal would be automatically killed within a couple of seconds without me manually killing it. I was confused as to why this was happening because as far as I could tell I hadn't changed my settings.json file in VS Code or User or Workspace settings and everything was running smoothly just minutes earlier. I was able to resolve that issue but I created a new minor inconvenience. Now whenever I open a file or folder in Integrated terminal it displays "sh-3.2$" instead of the current directory I'm in. If I type pwd and press enter it'll of course display the current directory I'm in but I don't want to have to type that a million times moving forward. If somebody could help me fix this issue I'd greatly appreciate it! I read some of the documentation online but I'm a new bootcamp student and I tried following along but it was going over my head. Thanks again!
I was reading a similar Stack Overflow question and they were saying to try and setup/configure my bash shell to have a prompt with path, specifically the PS1 environment variable, but I was confused on how to actually go about doing that.

How to open VSCODE with new file from command line and preserve prior state?

Using Visual Studio Code (latest version as well as prior versions), when using the command line to launch I am seeing some odd behavior. Trying to determine if I am missing something, or if this is a bug.
Here is the scenario.
Action 1: I have a workspace open with a couple of files open for editing. If I close VSCODE, and then just open it again the state is restored, I am in the workspace and the files are open for editing. Great.
Action 2: I have a workspace open with a couple of files open for editing. If I then from a command line do "vscode testfile.txt" then the new file gets opened in VSCODE and joins the other opened file. Great.
Action 3: I have a workspace open with a couple of files open for editing. I close VSCODE. I then from a command line do "vscode testfile.txt". VSCODE starts up, but only the new file gets opened in VSCODE. The workspace I had opened is not any more, and the files I had opened are no longer opened. Not so great.
I have tried adding the -r option on the command line but that didn't change anything.
This feels like a bug, but if not help me understand how I get the desired result, which is when VSCODE is not running, and I try to edit a file from the command line, I want VSCODE to restore to the state it was in when last closed, and then add that new file to the mix. Just like if it was already running.

Make Visual Studio Code open in clean state

I work in multiple projects spread in multiple folders on macOS.
I usually start working on them by running:
cd ~/workspace/project-a
code .
That always causes a new window to be open with the last files I worked on that project. My next move is to close all tabs, if the editor was split I have to do that as many times as split editors I had.
Is there a setting that would allow me to always start on a clean state?
My settings that I believe are related to this issue are the following:
"window.restoreWindows": "none",
"files.hotExit": "onExitAndWindowClose",
I tried off for files.hotExit but the behaviour remained the same.
Also if possible, where is this information stored (open files for given folders)? Is that a dot file inside the folder or elsewhere inside Visual Studio Code installation?
Make sure you are on the latest VSCode (1.24.1 as on 18-Jun-18)
Then make sure you have below in your settings
"window.restoreWindows": "none",
Make sure there are no JSON errors in your custom settings file. This also could cause the settings to be not loaded at all.
Next try launching the folder using
code -n .
Also $HOME/Library/Application Support/Code/Backups/workspaces.json contains the information of open workspaces
Also refer to below thread
Visual Studio Code always reopens previous file or folder
You could try, in addition of the setting "window.restoreWindows": "none" to start with:
code -n
That would force a new VSCode Window to be opened.
Also if possible, where is this information stored (open files for given folders)?
See issue 3884
# Windows
%APPDATA%\Code\Workspaces
# Mac
$HOME/Library/Application Support/Code
$HOME/Library/Application Support/Code/Workspaces
$HOME/Library/Application Support/Code/Backups/workspace.json
Window > Open Folders In New Window
set it to off

How to open multiples files in one Code instance from command line?

If I open a file in Visual Studio Code from the command line or from within File Explorer, each file will open in a separate Code instance. Is there a way to make them all open in the same instance? I.e. add them all to the 'Working Files' list?
Upcoming version will have a new option files.openInNewWindow which you can set to off to always open files into the last active instance. This is then identical to starting VS Code with the -r option but is much nicer to use (e.g. when you open a file from the desktop).
Update for our VS Code 1.0 release:
The setting is available as window.openFilesInNewWindow
You can use the command line option of -r or --reuse-window to assure it opens in the last active VS Code window
You can review the other options here
code Folder1/File1.txt Folder2/File2.java Folder3/File3.css
This command opens three files in one instance of the editor. All files are going to be added to the working files list.
This even works with much more files in the parameter list.

How to prevent Visual Studio Code from always reopening the previous files or folders?

Visual Studio Code always seems to remember my session and reopen the files and/or projects that were open the last time I used it. It obviously behaves correctly when running it from the command line with a file or folder supplied, but when opening from a taskbar shortcut, I'd like it to default to an empty environment.
Is there any way to change this behavior?
You can also go into your settings and use the following:
"window.reopenFolders": "none"
which will not reopen the folders you were working on when you closed the editor. The other options are one (the default) and all.
Edit 2017-11-09:
The option is now changed in latest versions.
"window.restoreWindows": "none"
See Mathieu DOMER's answer.
Edit 2018-09-12:
Another setting related to this is the hotExit setting. This has been discussed in this answer to a related question. To prevent reopening and remembering unsaved files, you can set this to:
"files.hotExit": "off"
But from the test I've made, when the window.restoreWindows setting is set to none, this is not needed. I haven't tested every possible combination, so YMMV.
And to answer a question in the comments, to edit the settings, you have to open the settings file. Some documentation can be found here (at least on the date I am writing this).
Edit 2022-03-16:
If you prefer using a GUI to change the settings, see D'Arcy Rittich's answer.
In VS Code:
for Windows/Linux Ctrl+, (or choose File/Preferences/Settings) to open the settings page.
for Mac ⌘+, (or choose Code -> Preferences -> Settings) to open the settings page.
then type restoreWindows in the Search settings input to filter for this setting. Set it to none and restart VS Code.
With latest update, it seems that the parameter has changed, now use:
"window.restoreWindows": "none"
You can add the -n option to the startup of VS Code and it will always start with an empty window, not restoring your previous session.
01 December 2018
This works for me. i.e. "C:\Users\Sampath\AppData\Local\Programs\Microsoft VS Code\Code.exe" -n
For me, none of above is working while I'm trying to close "dirty" unsaved files which I accidentally edited 1000 files and wanted to ignore saving all of them.
My fix was adding this line into settings.json:
"files.hotExit": "off"
Open up vscode, close vscode and just click the confirmation button to close all of the files without saving.
Then open back vscode and boom.. no more unsaved files being shown.
If "window.restoreWindows": "none" not solve the problem,then try to run code as root -> sudo code --user-data-dir code files and restart code normally without root.
Below worked for me
Right-click on Shortcut and add --disable-gpu to Target as per screen shot.
For me the only solution that worked was to go to the solution root and delete the .vs folder.
I reinstalled Visual Studio Code by downloading the latest update. I did not have to uninstall the previously installed Code. It work ok for me now.