I have vim storing my paging files in one local directory, having this in my .vimrc:
set directory=~/.vim/swap,.
Among other benefits, this makes it easy to find swap files right away. Now that my laptop is losing power or something else, and I'm starting a backup with a bunch of swap files, I just run my cleanswap script:
TMPDIR=$(mktemp -d) || exit 1 RECTXT="$TMPDIR/vim.recovery.$USER.txt" RECFN="$TMPDIR/vim.recovery.$USER.fn" trap 'rm -f "$RECTXT" "$RECFN"; rmdir "$TMPDIR"' 0 1 2 3 15 for q in ~/.vim/swap/.*sw? ~/.vim/swap/*; do [[ -f $q ]] || continue rm -f "$RECTXT" "$RECFN" vim -X -r "$q" \ -c "w! $RECTXT" \ -c "let fn=expand('%')" \ -c "new $RECFN" \ -c "exec setline( 1, fn )" \ -cw\! \ -c "qa" if [[ ! -f $RECFN ]]; then echo "nothing to recover from $q" rm -f "$q" continue fi CRNT="$(cat $RECFN)" if diff --strip-trailing-cr --brief "$CRNT" "$RECTXT"; then echo "removing redundant $q" echo " for $CRNT" rm -f "$q" else echo $q contains changes vim -n -d "$CRNT" "$RECTXT" rm -i "$q" || exit fi done
This will delete any paging files that are relevant to real files. Any that do not match are displayed in the vimdiff window, so I can merge my unsaved changes.
- Chouser
Chouser Sep 15 '08 at 14:20 2008-09-15 14:20
source share