Sublime Forum

Text file disappeared

#1

Where does Sublime store the text files?

Usually after I close Sublime, when I load it again I find the text in the state I left it.
But when I loaded it this morning, my 9000 words file that took months to write simply disappeared for reasons that I cannot fathom. How could that happen?

Doesn’t Sublime keep the file being written up to date as I go along and store it physically somewhere when it closes, and if so where, so that it be recovered?

Unless there is something I am missing here, this is a very risky program.

0 Likes

#2

Sublime Text stores unsaved file content in a session file, if hot_exit setting is set true.

The file is located at ~/.config/sublime-text/Local/Session.sublime_session on unix systems or in %APPDATA%\Sublime Text\Local on Windows.

ST normally keeps a autosave backup in the same folder to reduce risk of data loss.

However it is grossly negligent not to save important content to normal files, especially when working on it for month! That’s not the application to blame for data loss, IMHO.

see also: Failed Backup + Loss of Unsaved Files

0 Likes

#3

Windows. Sublime is installed in D:\Sublime. There is only a directory Data under it that has a Local directory under it which has only one file: session.sublime_session. Nothing other resembling your specification. I searched.

I agree it was somewhat irresponsible, but I am not used to programs that stay where I closed when I reload-them so that induced some carelessness.

The weird thing is the file has reappeared but if you ask me how, I have no idea – I am unaware of anything I did to recover it. (there was some sort of a second Sublime session open and I had to kill it w. task manager because it kept telling me it can’t close something and after that the file appeared. Do you understand any of this?

Now I will make a txt copy after every change, but to be safe rather sorry, given that I did not find the file you specified can you think of any other place where it might be located?

0 Likes

#4

My statement just assumed a normal setup due to lack of further information. A portable setup uses the Data folder, with exactly the same structure as the ones in user profile do.

Auto Save Session.sublime_session is created regularly while ST is running to ensure having a backup to role back if writing session.sublime_session fails.

That file not being present normally means ST closed normally before without any indication of saving the session file having failed.

If ST crashed during session file writing, the Auto Save Session could still be used to restore information.

There were some issues with automatic updater, which caused session file to currupt during ST upgrades, but those have been fixed in ST4.

Actually, I’ve never experienced any issues with the session file on Windows during the last 10 years of using ST, except in situations my disk ran out of space.

That of course doesn’t mean it can’t happen to others, but it is most likely related with external reasons such as hardware issues, permission issues or antivir programs blocking ST from doing its job.

Hence I wouldn’t second the statement of ST being a risky application.

0 Likes

#5

Thank you for the detailed explanation.

I figured no wp program would fail to create a backup–that would be more irresponsible than the user not saving changes.

I did find that file in the folder I described in the previous msg, but when I tried to open it, it was not readable text, so I did not recognize it as backup. I think I may have messed with trying to open it in Windows, which probably created the second session and made the text appear, that I was forced to close via Task Manager. But I can’t tell what the details were.

So my next question to you is: if smtg like this happens again (which I will prevent by saving after each change), how exactly do I recover the text from from that backup?

0 Likes

#6

I highly recommend using git for these types of workflows. You can stage files, you can commit files, save to a branch. The source control will keep a history of the changes as well as a way to revert back to any previous change. It is a life saver.

Another technique is to never store 9k words in a single file. Write them into separate files. Even a book publisher does not recommend turning in a whole manuscript in a single file.

0 Likes

#7

Sorry to bother you again, but I went over your past answer and it looks like there is something I do not understand.

I have 2 files in the D:\sublime\data\local:

Auto Save Session.sublime_session
Session.sublime_session

created at 10:09 and 10:10.

As far as I can tell they are not straight text, but I can see they contain the text unformatted.

Can you pls explain to an end user: if I need to recover the text, how do I use these files to achieve that?

Thanx.

0 Likes

#8

In case primary Session.sublime_session file got corrupted you can try to replace it with the Auto Save Session.sublime_session while ST is not running.

0 Likes

#9

Looks like “while sublime is not running” may be the key. I will try it later and see if I get a straight text file.

0 Likes

#10

Same story: text files disappeared unexpectedly. The recovery described above does not work. Has anyone figured out how the recovery works?

PS: The app was great, but now it’s really scary to use.

0 Likes

#11

The recovery process is well known; When you quit Sublime or close a window, the layout of each window is stored, which includes the list of files that are open, the cursor positions within them, any changes that have not been saved to disk, etc. This of course presumes that you have Sublime configured to do that (which is turned on by default).

That ends up in one of three places

  • If the window has a sublime-project open within it, then the state is stored within a sublime-workspace file with the same name as the project. The state is saved whenever you close the window OR quit Sublime

  • If you instead just use workspaces instead of projects, then you will have directly opened a sublime-workspace file, in which case the state is saved in that file directly. The state is saved whenever you close the window OR quit Sublime.

  • Windows that don’t have a project open in them have their data persisted into the session file, as outlined in posts above. This happens only when you quit Sublime; just closing a window throws the state of the window away. You will get prompted to save any changes when this is the case.

The next time Sublime starts/you open the project/you open the workspace, the saved state is restored back to how it was originally.

When that doesn’t work, it’s generally because:

  • It wasn’t actually saved; for example if you’re on MacOS where closing the last window that’s open in any application doesn’t actually quit the application. Thus nothing gets saved in that window (but if you had unsaved files open, you would be prompted to save them)

  • The session information/workspace file got corrupted, which is generally because of some external force, like not having enough drive space, or something outside of Sublime going wonky

If restoring the session from the auto-saved backup doesn’t restore things back, there’s not a lot that can be done about it after the fact.

The general rule of thumb is, if file content is worth keeping, it’s worth saving to disk in a more explicit way.

0 Likes

#12

After a few days of trouble all files were restored without any action on my part. What a relief!!!

Sublime Team, thanks a lot!

0 Likes