Loading ...
Sorry, an error occurred while loading the content.

125120Re: swap files reverting my work erroneously

Expand Messages
  • Gary Johnson
    Aug 2, 2011
    • 0 Attachment
      On 2011-08-02, Christian Brabandt wrote:
      > On Tue, August 2, 2011 3:27 pm, George Dinwiddie wrote:
      > > On 8/2/11 1:44 AM, Christian Brabandt wrote:
      > >> I have been thinking lately if it would be a good idea, if Vim would
      > >> only create a swap file, when it detects, that a change to the buffer
      > >> has been made. But not just when viewing a file.
      > >>
      > >> That is usually what happens a lot to me. I have 1 file open and in
      > >> another Vim instance I open the same file again only for viewing, so I
      > >> would like to avoid the "Attention" prompt.
      > >>
      > >> On the other hand I can see, that it is certainly useful, if you start
      > >> editing a file and immediately Vim warns you, that another Vim instance
      > >> is already editing that file. Hm, may be a new option swaponchange or
      > >> something?
      > >
      > > I'd just like to note that if you open the file in read-only mode (e.g.,
      > > with 'view <filename>'), then no swap file is created.
      > Yeah, if just my fingers would remember ;)

      I often encountered that problem in situations where I didn't have
      control over how Vim opened a file, so training my fingers wouldn't
      have helped. I often have several Vim instances open containing
      files I'm editing, so they have swap files. Then in one of those
      instances I'll use a tags command or a cscope command to find where
      a symbol is defined or used. If the symbol is in one of the files
      already open in a different Vim instance, I would get the swap file
      found error.

      I fixed that problem with the following SwapExists autocommand:

      if exists("##SwapExists")
      autocmd SwapExists * if v:swapcommand =~ '^:ta\%[g] \|^\d\+G$' | let v:swapchoice='o' | endif

      If the swap file exists and if the reason for opening the file is a
      tags or cscope command, the file is opened read-only.


      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
    • Show all 25 messages in this topic