recovery of a never saved file

11 views
Skip to first unread message

David M. Besonen

unread,
Jan 8, 2008, 5:31:06 PM1/8/08
to vim users
i use gvim 7.1 primarily on windows 2000.

if vim crashes while i'm editing a new file _but_ prior to my
having saved the file can i recover the edit session?

i imagine that i can recover the edit session from the "_.swp"
file that gvim creates. but i don't know how to associate a
.swp file with a text file so that attempting to edit the text
file (in the same directory as it's associated .swp file) will
trigger the gvim recovery process.

in other words, why can't i take example.txt.swp, rename it to
newname.txt.swp, and get gvim to initiate the recovery process
when i go to edit an empty newname.txt file?


thanks,
david


Matt Wozniski

unread,
Jan 8, 2008, 5:56:42 PM1/8/08
to vim...@googlegroups.com
On Jan 8, 2008 5:31 PM, David M. Besonen wrote:
>
> i use gvim 7.1 primarily on windows 2000.
>
> if vim crashes while i'm editing a new file _but_ prior to my
> having saved the file can i recover the edit session?

Yes. At a prompt, typing
vim -r
will give you a list of recoverable sessions in the current directory; typing
vim -r .swp
will recover from one of them, allowing you to save elsewhere.

> i imagine that i can recover the edit session from the "_.swp"
> file that gvim creates. but i don't know how to associate a
> .swp file with a text file so that attempting to edit the text
> file (in the same directory as it's associated .swp file) will
> trigger the gvim recovery process.
>
> in other words, why can't i take example.txt.swp, rename it to
> newname.txt.swp, and get gvim to initiate the recovery process
> when i go to edit an empty newname.txt file?

Unless the windows build of vim names things differently, you should
be able to rename .example.txt.swp to .newname.txt.swp to trigger
recovery the next time you edit newname.txt - but, at least on unix,
the names of swap files start with a leading "."; that's important.

~Matt

Ben Schmidt

unread,
Jan 8, 2008, 6:17:17 PM1/8/08
to vim...@googlegroups.com
> Yes. At a prompt, typing
> vim -r
> will give you a list of recoverable sessions in the current directory; typing
> vim -r .swp
> will recover from one of them, allowing you to save elsewhere.

Or do the same with the :recover command in Vim.

:recover .swp

Also, swap files are not always named what you expect, particularly if you have
multiple sessions editing the same file, or multiple unnamed buffers when you were
in the same working directory. To see the swap files, it might help to show
invisible files or folders in Explorer, or do DIR /A:H (I think...something like
that to show hidden files) at a command prompt.

Cheers,

Ben.


Send instant messages to your online friends http://au.messenger.yahoo.com

David M. Besonen

unread,
Jan 13, 2008, 2:43:55 PM1/13/08
to vim users
On Tue, January 8, 2008 2:56 pm, Matt Wozniski wrote:

> On Jan 8, 2008 5:31 PM, David M. Besonen wrote:
>>
>> i use gvim 7.1 primarily on windows 2000.
>>
>> if vim crashes while i'm editing a new file _but_ prior
>> to my having saved the file can i recover the edit
>> session?
>
> Yes. At a prompt, typing
> vim -r
> will give you a list of recoverable sessions in the current
> directory; typing
> vim -r .swp
> will recover from one of them, allowing you to save elsewhere.

thanks. that worked perfectly.

>> i imagine that i can recover the edit session from the
>> "_.swp" file that gvim creates. but i don't know how to
>> associate a .swp file with a text file so that attempting
>> to edit the text file (in the same directory as it's
>> associated .swp file) will trigger the gvim recovery
>> process.
>>
>> in other words, why can't i take example.txt.swp, rename
>> it to newname.txt.swp, and get gvim to initiate the
>> recovery process when i go to edit an empty newname.txt
>> file?
>
> Unless the windows build of vim names things differently,
> you should be able to rename .example.txt.swp to
> .newname.txt.swp to trigger recovery the next time you
> edit newname.txt - but, at least on unix, the names of
> swap files start with a leading "."; that's important.

i forgot to add the leading "." in my above example but i did
in fact include a leading "." in my testing. for whatever
reason, vim for windows does not seem to automatically recover
.swp files. the same .swp files will however be successfully
recovered when vim for windows is forced to recover them with
"vim -r .swp".


-- david


David M. Besonen

unread,
Jan 13, 2008, 2:48:30 PM1/13/08
to vim users
On Tue, January 8, 2008 3:17 pm, Ben Schmidt wrote:

>> Yes. At a prompt, typing
>> vim -r
>> will give you a list of recoverable sessions in the current
>> directory; typing
>> vim -r .swp
>> will recover from one of them, allowing you to save
>> elsewhere.
>
> Or do the same with the :recover command in Vim.
>
> :recover .swp

this technique doesn't seem to work with vim for windows.
possibly for the same reason that the automatic recovery based
on the correctly named files being present doesn't seem to work
with vim for windows.

but since vim -r .swp does work with with vim for windows i'm a
happy camper.


-- david


Tim Chase

unread,
Jan 13, 2008, 3:55:22 PM1/13/08
to vim...@googlegroups.com, vim users
>> :recover .swp
>
> this technique doesn't seem to work with vim for windows.

Though I'm away from my work (Windows) PC at the moment, you
might try

:recover _.swp

with the underscore which may do the trick for you. No
guarantees, but I remember the unnamed buffer being given the
name "_.swp".

-tim

Reply all
Reply to author
Forward
0 new messages