2

I don't understand the logic of recovering crashed edit files.

I frequently get the message "swap file exists" or something like that, due to a crash. So Vim will say something like "there is a swap file dated December 22" for a newer file dated "December 28" for example. Then it will give various options like edit anyway, recover, abort.

If your session crashed, then Vim recommends "recovering" the file. However, I don't see how this could be correct. If recovery involves overwriting the newer file with the old swap file, all that could do is destroy more recent edits, not recover them.

6
  • 3
    The idea is to recover before you make new edits. The swap file will have changes that weren't written to the file when Vim crashed, so recovering could actually preserve data.
    – Heptite
    Dec 30, 2021 at 17:46
  • @Heptite How could the swap file have new changes if the swap file is dated December 22 and the file itself is dated December 28? Dec 30, 2021 at 18:04
  • 3
    That's a problem, and suggests something else besides Vim has changed the file since the crash. In that case you create a copy of the file, do a recovery, and compare the recovered file with the copy.
    – Heptite
    Dec 30, 2021 at 19:58
  • The file was edited on the 28th December by a different editor. Vim just knows there is an edit that was never saved and want you to recover, no matter what file is newer. Apparently, Vim does not check the date between the files. It prompts for recovery, if it finds a swap file. Sep 29, 2022 at 9:08
  • 1
    @MartinBraun Vim does check the date, and it tells you if the saved file is newer than the swap. It just doesn't make any decisions based on this info: like you say, if it finds a swap file, it prompts for recovery.
    – Rich
    Sep 29, 2022 at 10:31

2 Answers 2

1

See :help usr_11.txt for documentation about recovery.

(There's something about warning when the file being newer than the swapfile in section 11.3 “Crashed or not?”)

0

Maybe you would like to see this great plugin: - vim-autoswap

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.