How to reopen last opened file in vscode - visual-studio-code

If i close the vscode editor after saving a file and reopen the editor again, the session is not restored. I am unable to find the file in open recent. The only way how can I open the file is navigating to the directory in open menu. Thats very annoying is it some problem with my editor or default behaviour?

You must have a folder opened to restore previously opened files.
Go to 'File' menu
Open folder
Select a folder (my documents for example)
Now open any files, close vscode and re-open. Your files are still in the editor.

"window.restoreWindows": "all" will do ;)

The complete settings are
"window.restoreWindows": "all",
"files.hotExit":"onExitAndWindowClose",
Note that with:
VSCode 1.42 (Jan. 2020) it does work even in case of "hot exit" (unexpected exits): see "Visual Studio Code never reopens previous file or folder".
VSCode 1.51 (Oct. 2020), that will also restore a search tab if you had one (issue 102659 resolved by issue 99694, and commit 8bf0e20)

Related

Remember previously open files when launching Visual Studio Code to edit a file

If I launch Visual Studio Code directly it remembers all the files I had open previously. The issue I have is if I (under Win10) right click a file and select "Open With Code". If VS Code is already open everything is file. If VS Code is not open, it will launch and open the file, but forget all the files I had previously opened.
This seems like unexpected (and non-consistent) behavior. Is there a way to get VS Code to launch from "Open With Code" but have it also open all the files I had opened previously? Basically, act the same as if VS Code was already opened when I clicked on "Open With Code".
Add the following line to your setting.json (Code Menu > Preferences > Setting)
"window.restoreWindows": preserve
This issue seems to cover exactly your case and has been resolved here

How to disable VSCode from remembering opened editors in the folder I opened before?

After I use VSCode to open a folder and some editors for the files, I close the folder. When I close and reopen the folder, VSCode opens the editors I opened last time.
How to prevent VSCode from reopening the editors I opened last time?
I have already set "window.restoreWindows": "none". When I exit directly from VSCode, it won't restore windows. I am saying when I reopen a folder, the editors I opened last time before I close the folder, will still be opened.
To stop Visual Studio Code from opening your previous folder all the time, then you have to edit settings.json.
To achieve this, open the settings.json. Do this by following the steps below.
Open the Command Palette by pressing F1.
Type, "Open settings".
When you see the options, select Open Settings (JSON).
After that, add the following option.
{
"window.restoreWindows": "none"
}
This should prevent Visual Studio Code from opening the previous folder when launching the application.
I just open vscode from my terminal, it's way faster and efficient in my opinion.
Just browse to your wished folder and write "code ." in your terminal.
Follow this process
Open VS Code, goto file>preferences>settings.
search for restore Window or click on Window tab then find restore window .select none from selection.
https://i.stack.imgur.com/FLx4a.png
https://i.stack.imgur.com/TAuHT.png
https://i.stack.imgur.com/B8W5a.png

VScode Folder automatically closes when vscode get closed

Before:
After:
When i am doing quit(cmd+Q) and reopening it, it loads the previous folder which i am working at, but if i press the top left red button and reopen everything is gone, i have to reopen the folder.
You can choose the corresponding settings in Window: Restore Window. Default is all
If you prefer the settings.json
"window.restoreWindows": "all"
Copied from vscode document:
Controls how windows are being reopened after starting for the first
time. This setting has no effect when the application is already
running.
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.
all: 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).
one: Reopen the last active window 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.

VSCode Switch Off Editor History

How to make VSCode to use only current project files when using dialog for quick file open by name or we always have to clean editor history so recent files won't be showing there?
This setting:
Search > Quick Open: Include History
Whether to include results from recently opened files in the file
results for Quick Open.
Uncheck it to set it to false.

Visual studio code, exclude directory from "go to file" option (ctrl + p)

I am using vscode, and I would like to exclude some directories (with webpack bundles) from 'go to file' option in vscode.
I tried to exclude them by "search.exclude" and "files.exclude". That worked in files tree and in search, but I still can find these files by 'go to file'.
Do you know how to do this?
As #adamesque stated, to exclude files from quick open you can either add them to files.exclude or search.exclude setting.
The issue then is that Quick Open also stores recent items, even from excluded paths.
Fortunately, VSCode now have a command File: Clear Recently Opened!
EDIT: As I needed to replace a Disk path while keeping my recent files I found where they are stored. It's in the storage.json file which is under /Users/imac/Library/Application Support/Code/storage.json on macOS and AppData\Roaming\Code\storage.json on Windows.
I thought I had this exact problem, and all the relevant issues I could find in the VS Code GitHub project seemed to have been fixed (see https://github.com/Microsoft/vscode/issues/19029, https://github.com/Microsoft/vscode/issues/6502).
In my case, because I had previously opened some of the files in those excluded directories, they still showed up in "Go To File" in the "Recently Opened" section, which made me think the exclusion feature wasn't working.
Turns out I just had to manually remove those items from history to keep them from showing up. Open the Command Palette, run Remove from History, and then select the a file to remove. You may need to do this for each file you'd previously opened from an "excluded" dir, but after this is done, they shouldn't show up anymore in the "Go to File" menu.
Hope this helps!
Version 1.44:
now we have an option in the settings.
If you tipe "Goto file" in the setting search bar, the editor opens up a Search:Exclude section, and you can add a folder or files.
CTRL + SHIFT + P, then select File: Clear Recently Opened