How do I prevent Visual Studio Code from opening with previously-opened files? - visual-studio-code

I've noticed that, despite always closing it before I quit, despite opening other files as well, Visual Studio Code will always re-open a particular file when I launch the app. This is still the case after upgrading to the latest version - 0.7.0 at the time of writing.
Is there a setting I'm missing, or something that needs to be cleared out / blown away?
I'm running on Windows Server 2012 R2.

This issue has been fixed for the next release and only shows up when you work in file mode and not folder mode (that is when you are not actually opening a full folder inside VS Code).
To workaround this, use the -n option when you run VS Code. -n will force to open VS Code empty without any file or folder opened.

Related

VS Code Failed to Install Visual Studio Code Update

I am trying to update my VS Code but am getting an error message: Updates may fail due to anti virus software and/or runaway processes.
A log file stemming from my Users was attached, but I am not sure what to check for. I am still new to computers and programming.
I copied the Code.exe file from where my program was installed and pasted it to the temp map: C:\Users\YOUR_USERNAME\AppData\Local\Programs\Microsoft VS Code
I reran the update and it works.
Run the update setup file, with a name like "CodeSetup-stable-...exe", in the following location:
C:\Users\<:User>\AppData\Local\Temp\vscode-update-system-x64
Replace <:User> with your username. And make sure VS Code is closed.
The same problem happened to me as well. It was because I installed VS Code in another directory other than the default location. The problem happened because after downloading the update in the Temp directory, VS Code tried to locate the previous installation in the default location to update it. As it failed, the update setup file remained with the temporary files. The problem was solved by manually installing the update.
This is how I resolved the problem:
Close VSCode.
Run VSCode AS ADMINISTRATOR by right clicking in the VS Code icon. This process opens VScode.
Now run the same VSCODE update as usual from inside VSCode.
VSCode closes after the update process and the latest VSCODE version is installed.
This happens because you installed VSCode in a specific directory, delete and download again but leave the default directory. This is because the update file looks for the default directory
This problem appeared to me because I moved the files of the setup of the vscode from Partition to another, and the solution was very simple. I opened the file that was in the path that appeared in the alert, and the problem was solved.
Just make sure any instance vscode was closed!

CMD-K in Visual Studio Code

I often clear the terminal on macOS with CMD-K (sort of equivalent to reset). When I use the terminal in Visual Studio Code and I press CMD-K, the banner at the bottom of the screen shows "(CMD-K) was pressed. Waiting for second key of chord..."
How can I make CMD-K pass through the editor to go to the terminal in Visual Studio Code?
I have occasionally run into this bug (VS Code on MacOS) and each time it randomly would fix itself until recently it kept persisting even through restarting my laptop. I have now found that closing all open projects seems to fix this issue for me.
Might be related to how VS Code stores your current workspace state (opened projects and file modifications). It seems maybe these state settings sometimes get corrupted somehow 🤔

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

Visual Studio Code on Mac

I installed Visual Studio Code on Mac/OSX (drop app in Applications)
- uninstalled (moved the App to the Trash)
- installed again
Since the second time I installed I didn't get the same start screen as during my first install I suppose somewhere in my file system Visual Studio Code writes something?
I would like to know where (besides in the Application folder) Visual Studio Code writes files?
VSCode uses another folder to store settings, including a flag to indicate if welcome should show or not. The folder is:
Windows: %APPDATA%\Code
Mac: $HOME/Library/Application Support/Code
Linux: $HOME/.config/Code
I've looked on my wife's mac and can't find a trace of these settings, they're not in any standard folder ($HOME, /Libraries/Preferences, /System/Libraries/Preferences nor /Libraries/Containers).
But to open the original start screen, you can use Help -> Show Welcome.
The settings are stored though, if you run "defaults read" you will see a number of settings related to vscode mentioned, including the files you had open last time you closed. Since Visual Studio Code uses the GitHub Atom Shell under the hood, you need to read the settings for atom using
defaults find atom
which will show you some data stored for the app.

Visual Studio Code: Auto-refresh file changes

Working with Visual Studio Code I have noticed if a file you are working with change, whenever that file get focused in a code panel it will be reloaded from the disk (if you don't have changes in the file through VSCode).
However, if you are on that file there is no alert to warning you about file changes.
I've been reviewing the settings and I cannot find anything like the visual studio option:
Detect when file is changed outside the environment
So my question: Is there any hidden setting or some hack to make that warning happen.
Update
Solved in version 0.3.0 of Visual Studio Code.
The file will be updated from disk if there is no changes through the editor. (very useful to read log files during a process execution)
If there are changes on both sides (from disk and through the editor) when ever you try to save the file using VSCode, the editor will warn you about that situation (i.e. "dirty writes") and a file comparison will allow you to decide what to do.
VSCode will never refresh the file if you have changes in that file that are not saved to disk. However, if the file is open and does not have changes, it will replace with the changes on disk, that is true.
There is currently no way to disable this behaviour.
{
"files.useExperimentalFileWatcher" : true
}
in Code -> Preferences -> Settings
Tested with Visual Studio Code Version 1.26.1 on mac and win
SUPER-SHIFT-p > File: Revert File is the only way
(where SUPER is Command on Mac and Ctrl on PC)
In version 1.57.1 (June 2021) there is still no setting like Detect when file is changed outside the environment.
But if the file was accidentally changed outside, you can easily revert the changes with just the Undo (Ctrl+Z) command
On Ubuntu, after creating a new file using vscode, it doesn't show up until I refresh the explorer manually. It's really frustrating. There was a key I changed in settings.json and everything worked fine after that:
"files.legacyWatcher": "on",
save, restart the vscode and be safe :)