Monday, August 1, 2011

Re: swap files reverting my work erroneously

Reply to message «Re: swap files reverting my work erroneously»,
sent 04:27:35 02 August 2011, Tuesday
by Gary Johnson:

> will tell you that it has found a swap file, etc. Regardless of you
> choice, Vim will use a new swap file for the current buffer, named
> .foo.swo. That file will be deleted at the end of your Vim session
> if you exit normally. The swap file from your previous Vim session,
> .foo.swp, will remain. That's the one you have to delete manually.
It is false: if I choose to delete swap file (in the vim prompt, not from shell)
it will use .foo.swp, not .foo.swo.

> > I think noswapfile will checked into my env repo. When you have 30+
> > buffers open, this is not very useful to me.
>
> I think that is a bad idea. Vim creates swap files to protect your
> data. They only persist after Vim has crashed, which is a good
> thing. Once you have decided to use their contents after a crash,
> or not, you can delete them and not be bothered with them until the
> next time Vim crashes.
I have swap files to prevent myself from editing one file in two vim instances
simultaneously. Though sometimes something goes wrong and vim or the whole
system crashes, but I never needed them to recover anything. All you need to
have the same behavior is to train yourself to do «paused for thinking - hit
{lhs of your mapping to :up} to save file». For me it happens even more times
then «stopped inserting - exit insert mode».

Original message:
> On 2011-08-01, David Ohlemacher wrote:
> > So once you have a swap file from a crash its there forever. That is
> > until you delete the swp manually. And if you hit recover, your newer
> > file contents will be wiped out by an older swap file's contents?
>
> It would be more correct to say that if you hit recover, the buffer
> will be filled from the swap file instead of the file you opened.
> Nothing has been wiped out. The contents of your file are unchanged
> from what they were before you opened the file.
>
> To easily see the difference between the current file contents
> (still on disk) and the recovered file content (in the Vim buffer),
> use DiffOrig. See
>
> :help DiffOrig
>
> You can now choose to replace the contents of the file on disk with
> the recovered contents from the crashed session, or conversely, you
> can choose to replace the contents of the Vim buffer with the
> contents of the file on disk. Your choice. And until you decide,
> no data has been lost.
>
> > I assumed (word chosen carefully), that once you've recovered from a swap
> > file, the swap would be updated to mirror the current buffer.
>
> The swap file in use _is_ updated to mirror the current buffer, but
> the swap file in use is not the same one you recovered from.
>
> For example, if you open foo and Vim crashes, there will be a
> .foo.swp file left in your current directory (assuming that you
> don't put your swap files elsewhere). If you open foo again, Vim
> will tell you that it has found a swap file, etc. Regardless of you
> choice, Vim will use a new swap file for the current buffer, named
> .foo.swo. That file will be deleted at the end of your Vim session
> if you exit normally. The swap file from your previous Vim session,
> .foo.swp, will remain. That's the one you have to delete manually.
>
> > I think noswapfile will checked into my env repo. When you have 30+
> > buffers open, this is not very useful to me.
>
> I think that is a bad idea. Vim creates swap files to protect your
> data. They only persist after Vim has crashed, which is a good
> thing. Once you have decided to use their contents after a crash,
> or not, you can delete them and not be bothered with them until the
> next time Vim crashes.
>
> Regards,
> Gary

No comments:

Post a Comment