Tuesday, February 1, 2011

Re: Help, please

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

No comments:

Post a Comment