🅭

Why it’s easier to recover unsaved documents in Kate than GEdit

A few years ago, I wrote about how I recovered a GEdit document from an unresponsive system. At the time, I couldn’t interact with the system using a keyboard and mouse. However, I could open a remote shell into the system and managed to retrieve and save the document.

I’ve not needed to do that since. My computer still occasionally becomes unresponsive, but I don’t lose hours’ worth of unsaved work anymore. I still occasionally need to recover my emails from RAM. So, what changed?

Shortly after GEdit crashed on me, I replaced it with Kate and KWrite. Kate has developer-oriented features whereas KWrite is a stripped-down version for general text editing. Both versions have the feature I’ll discuss in this article.

Kate has a feature that lets it recover your unsaved work from crashes and system crashes. It has two important caveats and I’ll get those out of the way first:

The recovery feature only works with documents that have been saved once and reside in a writable directory. Kate won’t be able to recover your never-saved novel or changes. The document needs to have a writable path on a file system.

When you make changes to a saved file on a local or remote file system in Kate, it auto-saves a swap-recovery file. The swap file contains all the differences between the original file on disk and the unsaved working copy you’re editing in Kate. It’s auto-saved to disk every 15 seconds. The swap-recovery file is saved to .example.txt.kate-swp in the same directory as the file. The leading dot hides the file in most file managers.

The swap file is removed when you save your document and make no further changes. However, if Kate or the system crashes, it’ll auto-detect the swap file when you reopen your file. Kate will prompt you to compare the current file with the unsaved changes and let you recover or discard them.

It’s a nice-to-have feature until the day when you really need it. It was really useful to me in the time before I fixed the suspend-on-low-battery issue that caused my laptop to crash fairly regularly (due to power failure).

I can hear some of my readers squirming in their chairs, ready to complain about the “unnecessary wear” on their solid-state drives (SSD). These occasional extra saves won’t wear out your SSD. SSD wear is caused by poorly designed programs that constantly write lots of data every millisecond for no apparent reason. Kate only saves the recovery file when there’s unsaved work to preserve; it doesn’t needlessly re-save it every 15 seconds.

You can turn off the swap-recovery feature or configure the auto-save interval in Kate Configuration: Open/Save: Advanced. You can also override where the swap file is saved. This last option can be useful if you’re editing files in a folder that is synced to other machines using a program like Syncthing or Dropbox.