Thursday, May 16, 2013

Re: vim: recover an unnamed file

On 2013-05-16, ping wrote:
> guys:
> My PC (ubuntu) just restarted by itself due to the (stupid) overheat
> issue, again (I couldn't find a solution on that in a year..)
>
> but regardless, I had a file that I had been editing for quite a while.
> all of a sudden the PC reloaded, now I'm wondering how can I recover
> that file.
>
> I tried both of the following method , but none of them give me the
> right file.
>
> one thing I've notice that if I'm in different folder, vim -r give me
> different files. I tried to change to different folder and invoke vim
> -r, but still failed to find the right one (per the timestamp) for
> me...
>
> any other good ideals?
>
> maybe the last resort, do I have to grep from the whole harddisk for this?
>
> and, what's the best practice to solve this issue in the future
> (lesson learned for me: always use a named buffer ) ?
>
>
> 1) :recover
>
> Swap files found:
> Using specified name:
> 1. .swa
> owned by: ping dated: Fri Jan 21 17:26:35 2011
> file name: [No Name]
> modified: YES
> user name: ping host name: 640g-laptop
> process ID: 14418
> 2. .swb
> owned by: ping dated: Wed Dec 29 14:32:22 2010
> file name: [No Name]
> modified: no
> user name: ping host name: 640g-laptop
> process ID: 7874
> 3. .swc
> owned by: ping dated: Fri Dec 17 17:05:02 2010
> file name: [No Name]
> modified: YES
> user name: ping host name: 640g-laptop
> process ID: 2735
> 4. .swd
> owned by: ping dated: Mon Dec 6 17:57:06 2010
> file name: [No Name]
> modified: YES
> user name: ping host name: 640g-laptop
> process ID: 22947
> 5. .swe
> owned by: ping dated: Fri Oct 29 08:15:23 2010
> file name: [No Name]
> modified: YES
> user name: ping host name: 640g-laptop
> process ID: 20799
> 6. .swf
> owned by: ping dated: Thu Dec 2 13:05:32 2010
> file name: [No Name]
> modified: YES
> user name: ping host name: 640g-laptop
> process ID: 5370
> 7. .swg
> owned by: ping dated: Sat Oct 23 11:38:18 2010
> file name: [No Name]
> modified: YES
> user name: ping host name: 640g-laptop
> process ID: 4930
> 8. .swh
> owned by: ping dated: Sat Oct 23 06:40:55 2010
> file name: [No Name]
> modified: YES
> user name: ping host name: 640g-laptop
> process ID: 3119
> 9. .swi
> owned by: ping dated: Sat Oct 16 23:28:22 2010
> file name: [No Name]
> modified: YES
> user name: ping host name: 640g-laptop
> process ID: 13572
> 10. .swj
> owned by: ping dated: Sat Oct 23 06:35:33 2010
> file name: [No Name]
> modified: YES
> user name: ping host name: 640g-laptop
> process ID: 4930
> 11. .swk
> owned by: ping dated: Tue Oct 12 10:15:05 2010
> file name: [No Name]
> modified: YES
> user name: ping host name: 640g-laptop
> process ID: 13672
> 12. .swl
> owned by: ping dated: Sun Oct 10 06:44:29 2010
> file name: [No Name]
> modified: YES
> user name: ping host name: 640g-laptop
> process ID: 26777
> 13. .swm
> owned by: ping dated: Wed Oct 6 00:44:37 2010
> file name: [No Name]
> modified: YES
> user name: ping host name: 640g-laptop
> process ID: 29373
> 14. .swn
> owned by: ping dated: Tue Oct 5 03:59:02 2010
> file name: [No Name]
> modified: YES
> user name: ping host name: 640g-laptop
> process ID: 29373
> 15. .swo
> owned by: ping dated: Sun Sep 26 09:34:44 2010
> file name: [No Name]
> modified: YES
> user name: ping host name: 640g-laptop
> process ID: 3824
> 16. .swp
> owned by: ping dated: Fri Apr 20 15:59:12 2012
> file name: [No Name]
> modified: YES
> user name: ping host name: 640g-laptop
> process ID: 17594
> In directory ~/tmp:
> -- none --
> In directory /var/tmp:
> -- none --
> In directory /tmp:
> -- none --
>
> Enter number of swap file to use (0 to quit): 0

After a quick look at Vim's memline.c, I think you are the victim of
poor housekeeping and a bug in Vim. You may still be able to
recover your files though.

Note that your oldest swap file is named ".swp", the next oldest is
named ".swo", and that pattern of decreasing last letters continues
through your newest swap file which is named ".swa". Note, too,
that your newest swap file is pretty old, from January 2011. I
doubt that that is the last time you used an unnamed buffer.

When Vim creates a swap file, it first tries the suffix ".swp". If
that file exists, Vim decrements the last letter and tries again.
When the suffix becomes ".swa" and that file exists, Vim then
decrements the second-to-last letter, sets the last letter to "z",
and tries again. It continues to look for swap file names that
don't exists until it reaches the suffix ".saa", then gives up.

Now, when Vim looks for swap files, it looks for files with suffixes
matching the pattern ".sw?". This will find only the first 16 swap
files. It ignores any swap files created with a second letter other
than "w".

That is a bug and needs to be fixed. Vim should either look for
swap files whose suffixes match the pattern ".s??" or stop creating
swap files with suffixes whose second letter is other than "w".

To your problem: It is quite likely that the same directories that
contain files named ".swa" also contain files named ".svz", ".svy",
and so on. Those are valid Vim swap files, but Vim doesn't
recognize them as such by those names.

I would suggest first verifying that you do not care about the files
matching the pattern ".sw?", then delete them. Then find the newest
file with a name matching the pattern ".s??", rename it to ".swp",
and try recovering it.

Once you've recovered all your files, I would suggest that you close
all instances of Vim and do a sweep of your file system using find
(not grep) to find all your swap files. Again be sure that you do
not need them, then delete them all. In the future, pay attention
to swap files left over after crashes and keep them cleaned up.

Regards,
Gary

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: