On 18/04/09 13:52, Michael Henry wrote:
[...]
> When I first started using Vim and got the 'Swap file exists' message, I
> found it very hard to understand the difference between the options
> presented. Several things were unclear to me:
>
> - If a previous Vim session crashed, did I lose any unsaved changes?
> How can I check?
Thanks to the swapfile, it may even be possible to recover unsaved
changes. But you must decide if you want to save them or lose them:
maybe you didn't save them because you had no _intention_ of making them
permanent.
How to check may depend on circumstances. A diff between the versions of
the file before and after recovery (or of one with a copy of the other)
is one possibility. Another possibility, as I said elsewhere, is that if
the ATTENTION message includes the line "modified: no", it means that
Vim believes there were no unsaved changes (but I don't guarantee that
"recovery" will always be a no-op in that case). Then if it says "NEWER
than swap file" it could be that you have a stale swapfile (maybe your
latest edit used 'noswapfile', or aswapfile in a different directory).
>
> - Why is recovery optional? Wouldn't Vim just know how to pickup where
> it left off?
Vim can't always tell where it left off; or you might have crashed Vim
manually in order to _stop_ changes that a mis-written or buggy
(possibly even buggy in the C code) function was making. Or (as noted
above), maybe you had no intention of saving those particular changes:
Vim cannot read your mind (and yes, recovery changes the editfile _on
disk_). There are so many variables (including the possibility of
editing without a swapfile) that YOU must make the final decision.
But maybe the best answer is: unlike some other software, Vim is clever
enough to know that it doesn't always know best.
>
> - Why is cleanup of dead swapfiles a manual step? Can't Vim figure that out?
It's not always obvious. For instance you may "recover", then change
your mind, then decide that you still want to recover... Or (depending
on circumstances and choice of options), the "dead" swapfile could be a
live swapfile for a file by the same name in a different directory. The
contents of the swapfile usually include the full path to the editfile
though; but in order to find that, the swapfile itself (not just its
directory entry) must be read.
>
> - What gets opened when I choose "Open Read Only" - the swapfile or the
> real file? What can I do with the read-only version once I open it?
The real file. If you used ":e filename" by habit but (this time) ":view
filename" would have served just as well, then you can still see the
contents. Or you might remember what was the last change you made; if it
is there, no need to recover (provided of course that no one else edited
the file in the meantime).
>
> - What happens if I Edit Anyway? Do I have a swapfile? Is that
> swapfile shared with another instance of Vim (which sounds bad)?
You have a swapfile with a different extension (.swo, .swn, .swm, etc.
the first one which doesn't yet exist. If there are already 48 swapfiles
for that single editfile (so that all of .swp to .swa are already
taken), you have a problem. (Or is it 1452 swapfiles, from .swp to .swa
then .svz etc. to .saa? I'm starting to doubt. But even 48 is "large
enough" that you ought not to need that many.) A Vim swapfile is never
shared between two instances, but if you "Edit anyway" you could be
sharing the _editfile_ between two instances, and each of them wouldn't
know about (and might remove) any changes made by the other. Especially
on a really big system (such as zLinux or zOS on an IBM mainframe) with
several workstations on the same filesystems. Or if the files being
edited are on a server PC which can be accessed concurrently from
several remote workstations (possibly other full-fledged PCs).
> How can I tell if I'm colliding with another live Vim instance instead
> of an old crashed one?
On Linux Vim will tell you that the process ID which last changed that
swapfile is still running, at least if it's running on the same machine.
On Windows it's less obvious, you may have to do some personal research.
Also on networked systems, where the other process might be on a
different machine.
>
> - How does Quit differ from Abort?
If you're typing ":e filename" or ":new filename" at the keyboard, there
is no difference. If the file is opened by a script though, Abort will
abort the whole script.
>
> Questions like these make it very hard to know how to proceed. I would
> have been comforted to see "Help" among the listed options. The message
> does suggest :help recovery, which has lots of good explanation about
> the options, but the user has to decide something before he can read
> that help. Perhaps a little more direct guidance would be helpful, such
> as "To understand the options below, please read :help recovery, either
> by starting a new instance of Vim or by choosing Abort below and
> restarting Vim without trying to open any files".
[...]
The relevant (and rather lengthy) help is at ":help ATTENTION" which is
also ":help E325". If confronted with a strange error message, always
check the help by the error number given at the start of the message.
The problem with a ":help" option would be the need to interrupt the
opening of the file to open a _different_ file (the helpfile). On a Tiny
version of Vim (which can use a swapfile but not split windows) the help
file couldn't even be opened in a different window.
Best regards,
Tony.
--
Banectomy, n.:
The removal of bruises on a banana.
-- Rich Hall, "Sniglets"
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---