Smarter Vim recovery? -


when previous vim session crashed, greeted "swap file ... exists!" each , every file open in previous session.

can make vim recovery prompt smarter? (without switching off recovery!) specifically, i'm thinking of:

  • if swapped version not contain unsaved changes , editing process no longer running, can make vim automatically delete swap file?
  • can automate suggested process of saving recovered file under new name, merging file on disk , deleting old swap file, minimal interaction required? when swap version , disk version same, should automatic.

i discovered swapexists autocommand don't know if can these tasks.

i have vim store swap files in single local directory, having in .vimrc:

set directory=~/.vim/swap,. 

among other benefits, makes swap files easy find @ once. when laptop loses power or whatever , start bunch of swap files laying around, run 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 q in ~/.vim/swap/.*sw? ~/.vim/swap/*;   [[ -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 )" \       -c w\! \       -c "qa"   if [[ ! -f $recfn ]];     echo "nothing recover $q"     rm -f "$q"     continue   fi   crnt="$(cat $recfn)"   if diff --strip-trailing-cr --brief "$crnt" "$rectxt";       echo "removing redundant $q"       echo "  $crnt"       rm -f "$q"   else       echo $q contains changes       vim -n -d "$crnt" "$rectxt"       rm -i "$q" || exit   fi done 

this remove swap files up-to-date real files. don't match brought in vimdiff window can merge in unsaved changes.

--chouser


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -