Monday, August 1, 2011

Re: swap files reverting my work erroneously

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

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