1
This is related to, but not solved by the question “How can I recover the original file from a .swp file?”.
I had two newly-created files a.txt
and b.txt
open in buffers. The active buffer was b.txt
, and I accidentally deleted a.txt
, and then switched to the buffer a.txt
. Unfortunately, I also have set autoread
and set autowrite
, so by reloading the buffer I emptied it.
I tried simply undoing the deletion in Vim by pressing u, but to no avail. Is there a way to recover the content of the deleted file from .a.txt.swp
? The solution to the linked question doesn’t work here, presumably because of autowrite
: the file is not restored.
In case it’s important, I also have set undofile
. Also, since the file was newly created in this Vim session, the .swp
file should, in principle, have contained the complete set of edits made to the file.
It is wrong to assume the full file contents exists in a
.swp
file. The unfortunate reality is that it does not. To slightly over-simplify, a Vim.swp
file only contains the necessary information to "rebuild" the changes in the file since the last write. If the original file is gone, not enough information exists for the.swp
file to be effective. – Heptite – 2014-08-13T02:11:31.437@Heptite That’s what I would assume as well but it seems to be wrong: in the linked question, the
.swp
file is enough to retrieve the deleted file. The only difference is that I haveauto{read,write}
active. Furthermore, since I have infinite undo active, there is no reason in principle why my file shouldn’t be recoverable: the state of the file before the last operation (= the deletion) should have been persisted to the undo file. – Konrad Rudolph – 2014-08-13T06:41:07.883There's only one answer that suggests that, and it contradicts itself. It needs to be reworded. And an undo file also does not contain the entire file contents. You may be able to recover some data by creating a blank file with the old filename and "recovering" it but you'll never get all of it. – Heptite – 2014-08-13T19:43:54.287
@Heptite Thanks for the explanation. Shame. Well, my system actually creates routine backups of all files, I was just unlucky enough to create, and then delete, the file just inside the one-hour window until the update would have been made. ;-) – Konrad Rudolph – 2014-08-13T20:10:12.097