Monday, April 9, 2012

Re: Swap file already exists

On 11:44 Mon 09 Apr , Eric Weir wrote:
>
> The last couple days I have been getting a "swap file already exists" message when I attempt to open a file. When that happens, as you are aware, the user is given several options, which to me are extremely confusing. A factor I feel certain is involved is that on a couple occasions either vim or a vim window was closed in other than normal fashion. [E.g., on one occasion, while I was running the computer on battery power, the battery ran down while I was away from my desk. Normally, when that happens the computer goes into suspend mode and when I attach the power cord the computer starts back up in the state it was in when it went into suspend mode. This time, however, it shut down. After restarting the computer I got the "swap file already exists" message when I restarted vim and attempted to load a file.]
>
> When I get the message I am never certain what to do. Usually I know that the file had been saved after the last edit. Even in that case i'm not sure what to do to open the most recently saved copy of the file. When I'm uncertain, I don't know which option will give me the most recent copy of the file. Or if I make the wrong choice, how I might recover---if that is possible at all.
>
> I imagine experienced programmer-users of vim would not have this problem. I am neither. I am a non-programming relative novice vim user. Help regarding my options and best choices in this situation would be greatly appreciated.
>
> Thanks,
> ------------------------------------------------------------------------------------------
> Eric Weir
> eeweir@bellsouth.net
>
> "Human coexistence and social life constitute the good common to us all
> from which and thanks to which all cultural and social goods derive."
>
> - Zygmunt Bauman
>
> --
> 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

Hi,

Vim saved all the changes you are making in a swap file. It is updated
automatically (see :help 'updatetime' and :help 'updatecount') - i.e. the
changes you made even after your last :write are there (though some changes
might not be there depending on 'updatetime' and 'updatecount' settings).

Now, when you open a file "./file.txt" such that the swap file exists (it
usually has the name "./.file.txt.swp" or "./.file.txt.swo" if the first name
already existed, which means you already ignored one swap file) then vim gives
you the swap exists message with several choices:
'o' Open read-only
'e' Edit anyway
'r' Recover
'd' Delete swapfile
'q' Quit
'a' Abort
where 'o' and 'e' will read the "./file.txt" and vim will create for it a new
swap file (usually "./.file.txt.swo" since "./.file.txt.swp" already exists on
your disc), the 'r' (Recover) will couse vim to read the "./.file.txt.swp"
file (which should be more recent than the actual file "./file.txt"), 'd' will
delete the swap file (usually you don't want this, unless you know that the
disc file is the one that you want), 'q' will quit vim and 'a' will abort the
operation (vim will still run).

You should carefully read ":help swap-file". There are some plugins which
helps with viewing the changes between the contents of the swap file and the
disc file, for example:
http://www.vim.org/scripts/script.php?script_id=3068

There are some other useful settings which you might want to follow, for
example how to set incremental backup with vim:
http://vim.wikia.com/wiki/Keep_incremental_backups_of_edited_files

Best regards,
Marcin

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