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

Re: swap files reverting my work erroneously

Expand Messages
  • ZyX
    Reply to message «Re: swap files reverting my work erroneously», sent 19:05:34 02 August 2011, Tuesday ... I started using vim and linux only a few years ago
    Message 1 of 25 , Aug 2, 2011
      Reply to message «Re: swap files reverting my work erroneously»,
      sent 19:05:34 02 August 2011, Tuesday
      by Gary Johnson:

      > I started using Unix and vi in 1985 in an environment where people
      > would inadvertently unplug serial cables or coaxial LAN cables, and
      > where occasional lightning strikes and careless backhoe operators
      > would take out our power. I got in the habit of saving my work
      > regularly.
      >
      > But now we have more reliable systems, and UPSs, and Vim with
      > automatic backups. My habits have changed. Now I save a file when
      > I'm done with a set of changes to it, not reflexively.
      I started using vim and linux only a few years ago and did not do any serious
      work before that needed reflexive savings. The reason why I do them is that I
      decided that it is a good habit because
      1. if it is a habit you don't need to think and thus loose exactly no time to do
      a save (I already paused typing; I don't do it just because I typed too much);
      2. software contains bugs. I observed unreproducible X crashes several times and
      thus I need to know that I won't loose my work if something like this happens. I
      have an UPS but it won't help here. You can say that systems are more reliable
      this time, but I never did real work on less reliable systems, so for me these
      few crashes are already too much. The only thing that will make me think that
      some system is reliable is a mathematically correct proof of this. You can't
      write it for C code and for this very bold GNU C Compiler, can you?

      Original message:
      > On 2011-08-02, Tony Mechelynck wrote:
      > > On 2011-08-02, Gary Johnson wrote:
      > >> On 02/08/11 06:38, ZyX wrote:
      > > >>>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».
      > > >>
      > > >>That's another good reason to use swap files. The trouble with
      > > >>continually saving, though, is that you lose your reference for the
      > > >>changes you've made to the file since you started editing. That's
      > > >>not always important, but sometimes it's very handy. And having
      > > >>swap files means I can do that without worry.
      > > >>
      > > >>Regards,
      > > >>Gary
      > >
      > > If you need a snapshot of a certain state of the disk file, take a copy.
      > > If you need successive snapshots, use numbered or dated backups, Vim
      > > supports them, after a fashion: see ":help backupext".
      >
      > Yes, I _can_ do that, and I do that on occasion, but I don't
      > _have_ to do that to have a reliable copy of the original state of
      > the file and of my changes. Not doing that, I don't have to deal
      > with the clutter of backup copies that need to be deleted at some
      > point. For long-term backup and history retention, I use a VCS.
      >
      > > I'm sure I'm not the only one on these lists who started editing at a
      > > time (and with an editor) where such luxuries as automatically recorded
      > > swapfiles simply didn't exist: for us old-timers, it has become a reflex
      > > to save the files whenever we stop editing (even if it's just to take a
      > > leak), and at least once every quarter-hour.
      >
      > I started using Unix and vi in 1985 in an environment where people
      > would inadvertently unplug serial cables or coaxial LAN cables, and
      > where occasional lightning strikes and careless backhoe operators
      > would take out our power. I got in the habit of saving my work
      > regularly.
      >
      > But now we have more reliable systems, and UPSs, and Vim with
      > automatic backups. My habits have changed. Now I save a file when
      > I'm done with a set of changes to it, not reflexively.
      >
      > Regards,
      > Gary
    • Gary Johnson
      ... 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
      Message 2 of 25 , Aug 2, 2011
        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
        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.

        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
      • Christian Brabandt
        ... Really nice. I ll add that to my config. regards, Christian -- You received this message from the vim_use maillist. Do not top-post! Type your reply
        Message 3 of 25 , Aug 2, 2011
          On Tue, August 2, 2011 5:39 pm, Gary Johnson wrote:
          > 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
          > 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.

          Really nice. I'll add that to my config.

          regards,
          Christian

          --
          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
        • Joan Miquel Torres Rigo
          ... If this happen and the swapfile results to be obsolete, then you could easily loose the (updated) contets of the file (if you accidentally save it). Also,
          Message 4 of 25 , Aug 3, 2011
            2011/8/2 David Ohlemacher <dohlemacher@...>:
            > 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?
            >
            > I assumed (word chosen carefully), that once you've recovered from a swap
            > file, the swap would be updated to mirror the current buffer.

            If this happen and the swapfile results to be obsolete, then you could
            easily loose the (updated) contets of the file (if you accidentally
            save it).

            Also, this obsolete swapfile may contains interesting changes not in
            the last version in disk and you could be interested in examine (and
            optionally merge) them.


            To handle this situations I use two mappings:

            command! Diff :w<space>!diff<space>-<space>%|less

            ...which lets me to examine the differences between the two files and
            decide if I want to use the swapfile version (:w), the disk version
            (:e %) or manually merge them starting from one or other.

            (I didn't know about DiffOrig mentioned by Gary below --but sure I
            will try it--)


            When resolved the conflict, I have this other mapping to drop the
            swapfile(s) easily and avoid future doubts.

            command! Recovered
            :!<space>rm<space>$(echo<space>%<space>|perl<space>-pe<space>'s/^(.*\/)?\.?(.*)$/\1.\2.swp\*/')

            ...this doesn't consider if there is more than one swapfiles and, off
            course, sure can be fully implemented without external commands. But
            it works for me ;-)


            Regards.

            --
            Joan Miquel Torres__________________________________
            Linux Registered User #164872
            http://www.mallorcaweb.net/joanmiquel
            BULMA: http://bulma.net http://breu.bulma.net/?l2301

            --
            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
          Your message has been successfully submitted and would be delivered to recipients shortly.