Start anew
[msysgit.git] / share / vim / vim58 / macros / diffwin.vim
blob5808c6b78dff55af2447c23baa6e0f32c1e3c37d
1 " diffwin.vim: a simple way to use diff to compare two source files
2 "                      and to synchronize the three windows to the current,
3 "                      next, and previous difference blocks.
4
5 "       Author : Charles E. Campbell, Jr.   (Charles.E.Campbell.1@gsfc.nasa.gov)
6 "       Date   : 9/22/2000
8 " To enable: put this file into your <.vimrc> or source it from there.
9 "               You may wish to modify the maps' temporary directory;
10 "               its easiest to use vms's version: copy it, then :s/tmp:/newpath/g
12 " To use: start Vim as shown below, use \df to generate differences,
13 "         and then hit the <F8> key:
15 "               vim -o newfile oldfile
16 "       \df
17 "               <F8>
19 " The resulting three windows will look like this:
21 "                            Diff Block Format:
22 "               +----+
23 "               |diff|          *** oldfilename date
24 "               +----+          --- newfilename date
25 "               |new |          ***************
26 "               +----+          *** #,# ****
27 "               |old |      how to convert new -> old (shows new stuff)
28 "               +----+      --- #,# ----
29 "                   how to convert old -> new (shows old stuff)
30 "                   ***************
32 " You can synchronize the files in the new&old windows to the current
33 " difference-block being considered: just move the cursor in the diff
34 " window to the difference of interest and hit the "\dc".  Use "\dn"
35 " (or "F8") and "\dp" to navigate to the next/previous difference block,
36 " respectively.
38 " Maps:
39 "  \df : opens a third window on top with the diff file.
40 "  \dc : synchronize windows to current  diff, cursor at new->old diff section
41 "  \dC : synchronize windows to current  diff, cursor at old->new diff section
42 "  \dn : synchronize windows to next     diff
43 "  \dp : synchronize windows to previous diff
44 "  \ds : reSet diff (re-runs diff on new/old/files)
45 "  \du : apply patch from down->up (old->new)
46 "  \db : apply patch from up->bottom (new->old)
47 "  <F8>: same as \dn
48 if version < 600
49   if has("unix")
50     map \df :let lzs1=&lz<CR><C-W>k:let tmpfile=tempname()<CR>:exe "!diff -c ".expand("#1")." ".expand("#2").">".tmpfile<CR><C-W>s:exe "e ".tmpfile<CR>:exe "!/bin/rm -f ".tmpfile<CR>:unlet tmpfile<CR>:set ft=diff<CR>gg:let &lz=lzs1<CR>\dn
51   elseif has("win32")
52     map \df :let lzs1=&lz<CR><C-W>k:let tmpfile=tempname()<CR>:exe "!diff -c ".expand("#1")." ".expand("#2").">".tmpfile<CR><C-W>s:exe "e ".tmpfile<CR>:exe "!erase ".tmpfile<CR>:unlet tmpfile<CR>:set ft=diff<CR>gg:let &lz=lzs1<CR>\dn
53   elseif has("vms")
54     map \df :let lzs1=&lz<CR><C-W>k:let tmpfile=tempname()<CR>:exe "!diff -c ".expand("#1")." ".expand("#2").">".tmpfile<CR><C-W>s:exe "e ".tmpfile<CR>:exe "!del ".tmpfile.";*"<CR>:unlet tmpfile<CR>:set ft=diff<CR>gg:let &lz=lzs1<CR>\dn
55   endif
56 else
57   map \df :let lzs1=&lz<CR><C-W>k<C-W>s:ene<CR>:exe "0r !diff -c ".expand("#1")." ".expand("#2")<CR>:set nomod<CR>:set ft=diff<CR>gg:let &lz=lzs1<CR>\dn
58 endif
59 map \dc :let lzs3=&lz<CR><C-W>k<C-W>k?^\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*$<CR>jYpdwf,DAGz<C-V><CR><Esc>"bYdd<C-W>j@b<C-W>k?^\*\*\*\*\*<CR>/^--- <CR>Ypdwf,DAGz<C-V><CR><Esc>"aYdd2<C-W>j@a2<C-W>k?^\*\*\* <CR>z<CR>:set nomod<CR>:let &lz=lzs3<CR>:echo "diff converts middle window to lower window"<CR>
60 map \dC \dc/^--- <CR>z<CR>:echo "diff converts lower window to middle window"<CR>
61 map \dn :let lzs4=&lz<CR><C-W>k<C-W>k/^\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*$<CR>j\dc:let &lz=lzs4<CR>
62 map \dp :let lzs5=&lz<CR><C-W>k<C-W>k?^\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*$<CR>?<CR>j\dc:let &lz=lzs5<CR>
63 if version >= 520
64   map \ds :let lzs2=&lz<CR>:wa<CR>2<C-W>k:exe "0r !diff -c ".expand("#1")." ".expand("#2")<CR>:set nomod<CR>:set ft=diff<CR>gg:let &lz=lzs2<CR><CR>\dn
65 else
66   map \ds :let lzs2=&lz<CR>:wa<CR>2<C-W>k:exe "0r !diff -c ".expand("#1")." ".expand("#2")<CR>:set nomod<CR>gg:let &lz=lzs2<CR><CR>\dn
67 endif
68 map <F8> \dc
70 " ---------------------------------------------------------------------
72 " Functions didn't enter vim until Version 5.2
73 if version >= 520
74   map \db :call DiffPatch(0)<CR>\ds
75   map \du :call DiffPatch(1)<CR>\ds
76   " DiffPatch: applies current patch section to newfile/oldfile
77   "  Uses anonymous register
78   "  Variables:
79   "    old2new: =1 DiffPatch being used to convert old -> new
80   "             =0 DiffPatch being used to convert new -> old
81   fu! DiffPatch(old2new)
82   
83     " use lazy updating
84     let lzs8=&lz
85     set lz
86   
87     exe "norm 2\<c-w>k?\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*$\<CR>j"
88     let newpat='\*\*\* \(\d\+\),\(\d\+\).*$'
89     let new1=substitute(getline("."),newpat,'\1',"")
90     let new2=substitute(getline("."),newpat,'\2',"")
91   
92     exe "norm /^--- \<CR>"
93     let oldpat='--- \(\d\+\),\(\d\+\).*$'
94     let old1=substitute(getline("."),oldpat,'\1',"")
95     let old2=substitute(getline("."),oldpat,'\2',"")
96   
97     if a:old2new == 1
98       exe "norm \<c-w>j:".new1.",".new2."d\<CR>"
99       exe "norm \<c-w>j:".old1.",".old2."y\<CR>"
100         let new1=new1-1
101         exe "norm \<c-w>k".new1."Gp"
102     else
103       exe "norm 2\<c-w>j:".old1.",".old2."d\<CR>"
104       exe "norm \<c-w>k:".new1.",".new2."y\<CR>"
105         let old1=old1-1
106         exe "norm \<c-w>j".old1."Gp"
107     endif
108   
109     let &lz=lzs8
110   endfunction
111 endif
113 " ---------------------------------------------------------------------
114 " vim:ts=4