" diffwin.vim: a simple way to use diff to compare two source files " and to synchronize the three windows to the current, " next, and previous difference blocks. " " Author : Charles E. Campbell, Jr. (Charles.E.Campbell.1@gsfc.nasa.gov) " Date : 9/22/2000 " " To enable: put this file into your <.vimrc> or source it from there. " You may wish to modify the maps' temporary directory; " its easiest to use vms's version: copy it, then :s/tmp:/newpath/g " " To use: start Vim as shown below, use \df to generate differences, " and then hit the key: " " vim -o newfile oldfile " \df " " " The resulting three windows will look like this: " " Diff Block Format: " +----+ " |diff| *** oldfilename date " +----+ --- newfilename date " |new | *************** " +----+ *** #,# **** " |old | how to convert new -> old (shows new stuff) " +----+ --- #,# ---- " how to convert old -> new (shows old stuff) " *************** " " You can synchronize the files in the new&old windows to the current " difference-block being considered: just move the cursor in the diff " window to the difference of interest and hit the "\dc". Use "\dn" " (or "F8") and "\dp" to navigate to the next/previous difference block, " respectively. " " Maps: " \df : opens a third window on top with the diff file. " \dc : synchronize windows to current diff, cursor at new->old diff section " \dC : synchronize windows to current diff, cursor at old->new diff section " \dn : synchronize windows to next diff " \dp : synchronize windows to previous diff " \ds : reSet diff (re-runs diff on new/old/files) " \du : apply patch from down->up (old->new) " \db : apply patch from up->bottom (new->old) " : same as \dn if version < 600 if has("unix") map \df :let lzs1=&lzk:let tmpfile=tempname():exe "!diff -c ".expand("#1")." ".expand("#2").">".tmpfiles:exe "e ".tmpfile:exe "!/bin/rm -f ".tmpfile:unlet tmpfile:set ft=diffgg:let &lz=lzs1\dn elseif has("win32") map \df :let lzs1=&lzk:let tmpfile=tempname():exe "!diff -c ".expand("#1")." ".expand("#2").">".tmpfiles:exe "e ".tmpfile:exe "!erase ".tmpfile:unlet tmpfile:set ft=diffgg:let &lz=lzs1\dn elseif has("vms") map \df :let lzs1=&lzk:let tmpfile=tempname():exe "!diff -c ".expand("#1")." ".expand("#2").">".tmpfiles:exe "e ".tmpfile:exe "!del ".tmpfile.";*":unlet tmpfile:set ft=diffgg:let &lz=lzs1\dn endif else map \df :let lzs1=&lzks:ene:exe "0r !diff -c ".expand("#1")." ".expand("#2"):set nomod:set ft=diffgg:let &lz=lzs1\dn endif map \dc :let lzs3=&lzkk?^\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*$jYpdwf,DAGz"bYddj@bk?^\*\*\*\*\*/^--- Ypdwf,DAGz"aYdd2j@a2k?^\*\*\* z:set nomod:let &lz=lzs3:echo "diff converts middle window to lower window" map \dC \dc/^--- z:echo "diff converts lower window to middle window" map \dn :let lzs4=&lzkk/^\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*$j\dc:let &lz=lzs4 map \dp :let lzs5=&lzkk?^\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*$?j\dc:let &lz=lzs5 if version >= 520 map \ds :let lzs2=&lz:wa2k:exe "0r !diff -c ".expand("#1")." ".expand("#2"):set nomod:set ft=diffgg:let &lz=lzs2\dn else map \ds :let lzs2=&lz:wa2k:exe "0r !diff -c ".expand("#1")." ".expand("#2"):set nomodgg:let &lz=lzs2\dn endif map \dc " --------------------------------------------------------------------- " Functions didn't enter vim until Version 5.2 if version >= 520 map \db :call DiffPatch(0)\ds map \du :call DiffPatch(1)\ds " DiffPatch: applies current patch section to newfile/oldfile " Uses anonymous register " Variables: " old2new: =1 DiffPatch being used to convert old -> new " =0 DiffPatch being used to convert new -> old fu! DiffPatch(old2new) " use lazy updating let lzs8=&lz set lz exe "norm 2\k?\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*$\j" let newpat='\*\*\* \(\d\+\),\(\d\+\).*$' let new1=substitute(getline("."),newpat,'\1',"") let new2=substitute(getline("."),newpat,'\2',"") exe "norm /^--- \" let oldpat='--- \(\d\+\),\(\d\+\).*$' let old1=substitute(getline("."),oldpat,'\1',"") let old2=substitute(getline("."),oldpat,'\2',"") if a:old2new == 1 exe "norm \j:".new1.",".new2."d\" exe "norm \j:".old1.",".old2."y\" let new1=new1-1 exe "norm \k".new1."Gp" else exe "norm 2\j:".old1.",".old2."d\" exe "norm \k:".new1.",".new2."y\" let old1=old1-1 exe "norm \j".old1."Gp" endif let &lz=lzs8 endfunction endif " --------------------------------------------------------------------- " vim:ts=4