5
votes
How frequently does vscode save dirty files?
trying to settle on a program where I can jot down stuff and have some degree of confidence that it will persist and I can't seem to find any actual documentation from vs code as to:
- How often unsaved files are saved so that they can be restored when a session is reopened
- if that frequency of how often they are saved can be configured?
Sidenote: I was going to ask this question on SO but apparently I am at risk of a question ban for not asking "good quality questions". Half my questions on there are from when I was a fresh developer and didn't really know how to articulate my questions well. Really changes my opinion of the openness of SO......
vscode has documentation that answers both of your questions: https://code.visualstudio.com/docs/editor/codebasics#_save-auto-save
If you're specfically asking about vscode's behavior of preserving dirty files that haven't been written to disk, I can't find any documentation either. But can offer the anecdote that I can't remember an instance of vscode failing to persist a dirty file across sessions in the 7 or so years I've used it.
A quick poke at VSCode calls it internally as an "untitled working copy", and new files get flagged as such: https://github.com/microsoft/vscode/blob/b4b2590456bd2e6326814ad3f1cdc8ab8f2357ca/src/vs/workbench/services/workingCopy/common/workingCopy.ts#L19-L24
The flag does a few things like not using the regular auto save logic: https://github.com/microsoft/vscode/blob/b4b2590456bd2e6326814ad3f1cdc8ab8f2357ca/src/vs/workbench/services/workingCopy/common/workingCopyBackupTracker.ts#L232
This looks to be part of the logic that handles untitled files and it fires off a save whenever the file is modified, and there's no tweakables among the files that handle untitled copies:
https://github.com/microsoft/vscode/blob/b4b2590456bd2e6326814ad3f1cdc8ab8f2357ca/src/vs/workbench/services/workingCopy/common/untitledFileWorkingCopy.ts#L200
The untitled files are saved by default in
%APPDATA%\Code\Backups\<random number>\untitled
, which gets changed immediately if you watch the directory whenever you open/close the editor and add/remove unsaved files to it:https://github.com/microsoft/vscode/blob/48ba01b5896376718aa66a11c60305cb105815c0/src/vs/workbench/services/workspaces/browser/workspacesService.ts#L167
thanks! i dont suppose if you know if this has actually been documented anywhere though?
Searching "untitled editor" yields the 1.42 release notes about Untitled editor improvements which is the closest you'll get aside from directly looking at the code itself, or ones scattered across other release notes that get displayed by default whenever VS Code updates.
A related code change is saving UI state like the currently opened files in #87158.
Given the nature of things like wikis and open source projects, things don't just appear out of thin air so feel free to contribute documentation changes to the project.
I am, which is why that link you provided is not related to my question.
This is about one step away from the same negative comment you made about SO above about poorly worded questions, from my POV.
A little more pleasantry ("hey, thanks for taking a moment to put together an answer, but...") and a little less matter-of-fact tone can really improve textual conversation online.
Do you need an IDE? Is this for code drafts or just notes?
I used Sublime for my quick notes. Over 2 years I've never had it lose stuff. I don't even bother saving most of the time it just maintains each tab I have as a buffer between sessions.
Second sublime. And if you're allergic to save, there's no need to pay for it -- the notification that asks you to buy pops up every 5 saves.
Folks severely underestimate the power of Sublime's theming and color scheme engines. There are a lot of nice options out there.
Nothing gets lost? I can write in a file, not save, restart the computer and continue editing from where I was.
Using it in my day job and while I’m not a personal fan, it’s really reliable.
it doesn't prompt you to save your unsaved files? (that's been my experience)
I just tested in my VSCode:
If I close the tab holding this text it asks if I want to save the file.
ahhh ok I see.
normally when I am closing something, it's a "window" or a "project" and not the entirety of vscode
(X button vs File -> Exit)
If you have multiple windows open and close 1 of them, I don't believe you get this autosave functionality
FTFY
And correct. which is why all my unsaved files are in the same windows which I close last when I am done with my computer.
got it, thanks for the explanation!
I'm not sure what you mean. Unsaved files, as in files you did not explicitly save in, are just not saved at all. There is no backup. It's gone.
Files that ARE saved are written to disk immediately.
It's a code editor, in the end, not Microsoft Word, so it's necessary that something like "is the file written to disk" be as transparent as possible.
I'm sure there's a setting or extension that will just write the file to disk in the background periodically, but I'm not sure that's what you're after.
Open up VS Code, open a new file, type in random words and then close your VS code and then open it back up, that unsaved file with those random words will be persisted.
well there's a difference between open, write something, close and open, write something, computer crashes
in the first case, it will probably prompt you "do you want to save your files" and if you say no it will (understandably) delete your unsaved files
in the second case, it will retain the locally-saved copies
If you use Discord already, maybe jotting down notes in a server that you create and never invite anyone else to might be a good strategy for making sure you never lose anything; you can make a bunch of channels organized into categories and then write notes there which will be persisted to their servers.
although if you require open source, I don't know of anything that will let you create a file, not save it, manually close the program, and expect it to still be there when you re-open
VS Code does not prompt you if you have only 1 windows open with unsaved files.
I'd recommend Notepad++ for this use case because it starts up in under a second. I don't save anything in n++ I just rely on its autosave and I never lose anything.
Sublime is also a good choice, but for me Sublime is about 1 second to start up and has some learning curve whereas npp is dead simple and quick.
VSC only if you need all its features (e.g. it's a good choice as a markdown editor) but not for simple text notes, it's overkill & too slow for that
I am on Linux
it's not open-source
Is the open source thing about money or principles?
I only ask because VSCode is open source but Microsoft is.... Microsoft.
I used Sublime throughout grad school without a license (which they permit). The cost is minimal and I bought a license when I got my first big boy paycheck because it is an excellent product.
Are you basically arguing that that an open-source license on a codebase can't be trusted depending on who works on it?
VSCode is "kind of" Open source https://github.com/microsoft/vscode/wiki/Differences-between-the-repository-and-Visual-Studio-Code.
There are plenty of "Open source" projects you cannot really build from the source. Many services only open source the client, or parts of the server, or things like that. Its often called Open Core business model.
hence why I use VSCodium
It is open-source, but the open-source version of the program is only if you bother to compile it yourself. Otherwise, it contains some Microsoft binaries – this is mainly why https://github.com/VSCodium/vscodium exists.
yea, that's why I use vscodium now.
Just saying Microsoft isn't exactly the GNU Foundation. But if you want access to the code base, then VSCode checks the box.
What does that have to do with anything? the CIA could release a really useful tool and if it has the open-source license, I see no reason not to trust it.
you should mention these requirements when you post a question.