How to recover files after vim crash?

803 views
Skip to first unread message

robert song

unread,
May 28, 2010, 1:36:54 AM5/28/10
to vim...@googlegroups.com
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

Christian Brabandt

unread,
May 28, 2010, 2:15:02 AM5/28/10
to vim...@googlegroups.com
On Fri, May 28, 2010 7:36 am, robert song wrote:
> Sometimes vim freezes by some mis-operation, and I should kill it.

That really shouldn't happen. In what context does this happen to you?

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

Not sure. You can probably script something like this. May be, it works
already when including the % in your viminfo file.

regards,
Christian

Tony Mechelynck

unread,
May 28, 2010, 1:26:26 PM5/28/10
to vim...@googlegroups.com, robert song

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

Ben Fritz

unread,
May 28, 2010, 2:05:39 PM5/28/10
to vim_use


On May 28, 1:15 am, "Christian Brabandt" <cbli...@256bit.org> wrote:
> On Fri, May 28, 2010 7:36 am, robert song wrote:
> > Sometimes vim freezes by some mis-operation, and I should kill it.
>
> That really shouldn't happen. In what context does this happen to you?
>

As an additional note, most operations in Vim, can be cancelled or
aborted by pressing CTRL-C. I very rarely need to kill Vim (sometimes
when I loose my network connection while editing a file on a mapped
drive to a ClearCase file system, but that's about it).

Christian Brabandt

unread,
May 28, 2010, 2:33:21 PM5/28/10
to vim...@googlegroups.com
Hi Tony!

On Fr, 28 Mai 2010, Tony Mechelynck wrote:

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

Forgive me for shamelessly mentioning my recover.vim Plugin
http://www.vim.org/scripts/script.php?script_id=3068
It will open automatically a diff window whenever it detects, that for a
file already exists a swap file.

regards,
Christian

Reply all
Reply to author
Forward
0 new messages