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.
.swpfile. The unfortunate reality is that it does not. To slightly over-simplify, a Vim.swpfile 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.swpfile to be effective. – Heptite Aug 13 '14 at 02:11.swpfile 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 Aug 13 '14 at 06:41