Tuesday, May 31, 2011

Re: Restore file from undo

On Tue, May 31, 2011 12:23 am, Vsevolod Velichko wrote:
> Hello all!
>
> Please, help me with the following:
> I've accidentally lost the folder with source code I wrote, but I have
> vim undo-file for each file I've lost.
> However, when I try to create new file with the same name as it had
> before deletion, vim tells me that there's no undo/redo history.
>
> Is there any way to replay the history from undo-file to recreate all
> the files I had?
>
> Thanks in advance.

You can't. When reading the undo history, vim checks, that
the checksum between the undo-file and the current open file match and
that their line numbers are the same, if not, Vim will complain with
an error (if you have set verbose to a value larger than zero).

Even if you'd patch vim, to not check the hash size and number of lines
it wouldn't work, because the undo file does not contain the whole file
content, but only the content that changed between each file change.
So if you changed the source of vim, you could only recover the lines
that you actually changed, but all the lines that were not changed (and
therefore not recorded in the undofile) would still be lost.

That would only work, if you had previously reloaded your whole buffer
using :e! and 'undoreload' was set to a negative number (or you file
contained less than that number of lines). If you know, the whole
file content was previously saved in your undofile and you'd like to
try out reloading your changes, let me know. I made a patch, that
enables you to force reloading the undo history, which you could try out
if you want. But that is not very useful by itself.

regards,
Christian

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment