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

Re: Help, please

Expand Messages
  • Ben Schmidt
    ... I do it a bit more easily: 1) Open the file with -r to recover 2) :DiffOrig (:help :DiffOrig) 3) Fix it up however I want 4) :w 5) :!rm
    Message 1 of 8 , Feb 1, 2011
    • 0 Attachment
      > I've occasionally wished for a "--wtf" option to vim that would
      > effectively open both the unrecovered and recovered versions in a
      > diffsplit allowing me to compare them. Currently I have to
      >
      > 1) open the file with "-r" to recover
      > 2) write the file to a temp file
      > 3) quit vim
      > 4) delete the swapfile (remembering "/a" on Dos/Win32)
      > 5) vimdiff the original and the temp file
      > 6) make any fixes and save the file back out
      > 7) delete the tempfile
      >
      > Some easy means to do steps 1-5,7 would be most welcome.
      >
      > -tim

      I do it a bit more easily:

      1) Open the file with -r to recover
      2) :DiffOrig (:help :DiffOrig)
      3) Fix it up however I want
      4) :w
      5) :!rm the-name-of-the-swapfile.swp

      And actually, I use the shell script below whenever I have a system
      crash (which is usually because I remove the battery at an inopportune
      moment...). It finds Vim swap files in the current directory, opens each
      file in Vim in turn, and then prompts me to delete the swapfile after I
      exit Vim. So that pretty much cuts out steps 1 and 5. Makes life pretty
      sweet.

      I wonder if there is something like this on the Vim Tips wiki, or
      whether it would be worth adding.

      Ben.



      #!/bin/bash
      SWAPS=`find . -name '.sw?' -or -name '.*.sw?'`
      N=1
      while true
      do
      SWAP=`echo "$SWAPS" | tail -n +$N | head -n 1`
      if [ "$SWAP" = "" ]
      then
      break
      fi
      REAL=`echo "$SWAP" | sed -E 's/(^|\/)\.([^/]*)\.sw.$/\1\2/'`
      N=$(($N+1))
      if [ "$SWAP" = "$REAL" ]
      then
      vim -r "$SWAP"
      else
      vim "$REAL"
      fi
      if [ -f "$SWAP" ]
      then
      read -e -p "Delete the swap file?" DELETE
      if [ "$DELETE" = "y" -o "$DELETE" = "Y" ]
      then
      rm "$SWAP"
      fi
      fi
      done



      --
      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
      ... Forgive me for shamelessly mentioning my plugin recover.vim http://www.vim.org/scripts/script.php?script_id=3068 But that was exactly the reason why I
      Message 2 of 8 , Feb 1, 2011
      • 0 Attachment
        On Tue, February 1, 2011 12:41 pm, Tim Chase wrote:
        > I've occasionally wished for a "--wtf" option to vim that would
        > effectively open both the unrecovered and recovered versions in a
        > diffsplit allowing me to compare them. Currently I have to
        >
        > 1) open the file with "-r" to recover
        > 2) write the file to a temp file
        > 3) quit vim
        > 4) delete the swapfile (remembering "/a" on Dos/Win32)
        > 5) vimdiff the original and the temp file
        > 6) make any fixes and save the file back out
        > 7) delete the tempfile
        >
        > Some easy means to do steps 1-5,7 would be most welcome.

        Forgive me for shamelessly mentioning my plugin recover.vim
        http://www.vim.org/scripts/script.php?script_id=3068
        But that was exactly the reason why I wrote it.

        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
      • Ben Schmidt
        ... Sorry, should ve said in the current directory and below (it recurses). And that to delete the swap file you must enter y or Y, anything else will leave it
        Message 3 of 8 , Feb 1, 2011
        • 0 Attachment
          On 1/02/11 11:17 PM, Ben Schmidt wrote:
          >> I've occasionally wished for a "--wtf" option to vim that would
          >> effectively open both the unrecovered and recovered versions in a
          >> diffsplit allowing me to compare them. Currently I have to
          >>
          >> 1) open the file with "-r" to recover
          >> 2) write the file to a temp file
          >> 3) quit vim
          >> 4) delete the swapfile (remembering "/a" on Dos/Win32)
          >> 5) vimdiff the original and the temp file
          >> 6) make any fixes and save the file back out
          >> 7) delete the tempfile
          >>
          >> Some easy means to do steps 1-5,7 would be most welcome.
          >>
          >> -tim
          >
          > I do it a bit more easily:
          >
          > 1) Open the file with -r to recover
          > 2) :DiffOrig (:help :DiffOrig)
          > 3) Fix it up however I want
          > 4) :w
          > 5) :!rm the-name-of-the-swapfile.swp
          >
          > And actually, I use the shell script below whenever I have a system
          > crash (which is usually because I remove the battery at an inopportune
          > moment...). It finds Vim swap files in the current directory, opens each
          > file in Vim in turn, and then prompts me to delete the swapfile after I
          > exit Vim. So that pretty much cuts out steps 1 and 5. Makes life pretty
          > sweet.

          Sorry, should've said in the current directory and below (it recurses).

          And that to delete the swap file you must enter y or Y, anything else
          will leave it (better safe than sorry).

          And it's probably horribly unportable, and not nicely written, and
          horribly documented (i.e undocumented), but it was basically hacked
          together once I got sick enough of recovering swap files more manually,
          and it works for me on Mac OS X.

          So I don't really want to promote it...but if it helps you, great!

          > I wonder if there is something like this on the Vim Tips wiki, or
          > whether it would be worth adding.

          And by 'it' I mean something like this, not this as it stands....

          Grins,

          Ben.



          > #!/bin/bash
          > SWAPS=`find . -name '.sw?' -or -name '.*.sw?'`
          > N=1
          > while true
          > do
          > SWAP=`echo "$SWAPS" | tail -n +$N | head -n 1`
          > if [ "$SWAP" = "" ]
          > then
          > break
          > fi
          > REAL=`echo "$SWAP" | sed -E 's/(^|\/)\.([^/]*)\.sw.$/\1\2/'`
          > N=$(($N+1))
          > if [ "$SWAP" = "$REAL" ]
          > then
          > vim -r "$SWAP"
          > else
          > vim "$REAL"
          > fi
          > if [ -f "$SWAP" ]
          > then
          > read -e -p "Delete the swap file?" DELETE
          > if [ "$DELETE" = "y" -o "$DELETE" = "Y" ]
          > then
          > rm "$SWAP"
          > fi
          > fi
          > done



          --
          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
        • Benjamin R. Haskell
          ... Personally, I find the first listed advantage to be the best: - You will not pollute the directories with .swp files. To avoid the first listed
          Message 4 of 8 , Feb 1, 2011
          • 0 Attachment
            On Tue, 1 Feb 2011, Tim Chase wrote:

            >> I apologize for being ornery. I have had to deal with Windows and
            >> AT&T lately. I will do better.
            >
            > Heh, either Windows or AT&T alone is enough to boil one's blood, so I
            > can sympathize and appreciate the occasional bad day. :)
            >
            >> I'm aware of most of the options in vim. I'm not aware of any option
            >> to put the swapfiles elsewhere. That would also work.
            >
            > Vim does provide the 'directory' option
            >
            > :help 'directory'
            >
            > which can be used to put the swapfile in the first directory in the
            > listing. For warnings, read below
            >
            > :help E326
            >
            > on the advantages/disadvantages to changing this. The only times I've
            > used this was back when floppy-drives were the norm, and having a
            > swapfile on a floppy was agonizingly slow.

            Personally, I find the first listed advantage to be the best:
            - You will not pollute the directories with ".swp" files.

            To avoid the first listed disadvantage...
            - You can get name collisions from files with the same name but in
            different directories[...]

            ...I use a 'directory' setting ending in two directory separators:

            set dir=~/.vim-tmp//

            Then, as described at :help 'dir', I get swap files with directories
            "embedded" with percent signs in place of directory separators, e.g.:

            ~/.vim-tmp/%home%bhaskell%tmp%compile%saved-test-1277816925.swp

            This would keep swap files out of your Dropbox directory (in addition to
            the other benefits). The only drawback is the second disadvantage
            listed in :help E326, that another person editing the same file won't
            see your swap file if it's in your home directory. (But you have that
            problem anyway if the other user doesn't use Vim, for example.)

            --
            Best,
            Ben

            --
            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
          • Benjamin R. Haskell
            ... I guess I didn t read the initial problem closely enough... Another possible option is to kill the running Vim process on computer A. For example, I
            Message 5 of 8 , Feb 1, 2011
            • 0 Attachment
              On Sat, 29 Jan 2011, Ed Bradford wrote:

              > I use DropBox. I edit a file on computer "A" and FORGET to exit vim.
              > Now on computer "B", the .swp file prevents me from editing. I know I
              > can ignore and just to go computer. However, VIM and DropBox could
              > solve my problem by having an option to update on 1,4,16,64,256 second
              > intervals and abandoning the lock file that is the .swp file. DropBox
              > has solved the SYNC problem. Please embrace it and make DropBox and
              > VIM work as people WANT, not as developer's expect.

              I guess I didn't read the initial problem closely enough...

              Another possible option is to 'kill' the running Vim process on computer
              A. For example, I work on things on my work computer from both home and
              work. If I leave a file open in Vim while at work, and go to edit it
              when I'm home, I get the recovery message.

              Often I won't have made any changes since the time I last saved, in
              which case it's perfectly fine to 'kill' the running Vim.

              E.g.:

              work$ vi ~/some.file
              [leave running]

              [later, at home]
              home$ ssh work
              work$ vi ~/some.file
              E325: ATTENTION
              Found a swap file [...]
              ...
              modified: no
              ...
              process ID: 10287 (still running)
              (choose 'A' for (A)bort)
              work$ kill 10287 # just 'kill' (which defaults to 'kill -TERM'), not 'kill -9'
              [running vim is safely shut down]
              work$ vi ~/some.file
              [edit as normal]

              --
              Best,
              Ben

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