Restore vim file from .un ~ file without cancel command

How to recover vim file from undo file without pressing undo ?

I had a vim file that I saved when adding text. Then I ran a python command that emptied the contents of the file, and I can see some words contained in the .un~ file. When I try to undo in the file, it says Already at latest change . I cannot find the swap file in my swap file directory.

+6
source share
2 answers

You can not. The failure information is related to Vim's latest knowledge of the contents of the file; when they no longer match, Vim cannot reapply the changes. This is documented :help undo-persistence :

Vim discovers that the cancellation file is no longer in sync with the file that was written for (with a hash of the contents of the file) and ignore it when the file was modified after the cancellation file was written to prevent damage.

The best you can do is try to manually save the recognized bits in the undo file, for example. with hex editor or Vim binary mode.

+7
source

This is not entirely possible, since the undo file contains only text that has been changed in one change. If at some point you reloaded the file, undofile should contain a full buffer for this and starting from it you can theoretically restore the file (by going through the cancel states).

I already wrote about this on the vim_use mailing list here and here (which even contains a patch that allows you to force read in an undo file)

You can try installing vim and see if you can recover at least some data.

+4
source

Source: https://habr.com/ru/post/953215/


All Articles