Friday, May 28, 2010

Re: How to recover files after vim crash?

On 28/05/10 07:36, robert song wrote:
> Hi, everyone.
>
> Sometimes vim freezes by some mis-operation, and I should kill it.
>
> In this way, all the opened file are lost, Is it able to reload the
> files once again after I open the vim just like the session-manager in
> firefox?
>
> Best Regards,
> robert
>

You usually can, unless you have forbidden the use of swapfiles (see
:help 'swapfile').

For that, you must know which files were being edited. This is easy in
two cases:
- There was only one, or only a few, and you remember which ones
- Vim was loaded from a session file (either made with :mksession, or a
custom one made by hand)

In that case, you can just restart Vim with the same files, and as each
file is opened Vim will give you a rather long ATTENTION message with a
prompt at the end (see ":help ATTENTION", a rather long help topic: it
is worth reading it all), meaning it has found a "swap file" for that
file, which in turn means that an edit of that file has somehow not been
completed.
- If Vim says "(still running)" (usually only on Unix-like systems) it
means that there is another Vim still editing that file on the same
machine. In that case you will want either to (a)bort or to (o)pen
readonly but NOT to mess with the swapfile used by that other Vim.
- Otherwise:
- Any file for which Vim says "modified: no" had either not been
changed, or already been saved. Answer (d)elete, you don't need the swap
file.
- If Vim says "modified: YES" but not "NEWER than swap file", answer
(r)ecover; then before you save the changes, use the :DiffOrig command
(which is described under :help :DiffOrig and is defined by the
vimrc_example.vim) to compare the file before and after recovery. If the
changes are what you expect, you can save the new version, and then
immediately reload it to (d)elete the now obsolete swap file.
- For the "NEWER than swap file" case, see the help (somewhere under
|ATTENTION|, at usr_11.txt line 198 in the latest Vim 7.3a help).

If that crashed edit session were editing any files whose names you
can't recall, the ATTENTION message will appear the next time you (or
someone) edit them. When that message appears, react as above. With the
default setting (swap file in the same directory as the editfile), the
swapfile won't get lost, and even if you let that crashed editfile sleep
for six months before editing it again, it can still be recovered then
if necessary.

See also ":help :recover" and ":help -r".


Best regards,
Tony.
--
When I was a kid I said to my father one afternoon, "Daddy, will you
take me to the zoo?" He answered, "If the zoo wants you let them come
and get you."
-- Jerry Lewis

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