X-Git-Url: http://git.iain.cx/?p=profile.git;a=blobdiff_plain;f=.vim%2Fscript%2Fmerge;fp=.vim%2Fscript%2Fmerge;h=ad7c083941465fcf892ace31684e2dc8e39054f3;hp=0000000000000000000000000000000000000000;hb=f1c41dc95f2d4fe411e00c35b0b7571178a149a1;hpb=3f3bc49b281988f04653f35e777d375f49398a77 diff --git a/.vim/script/merge b/.vim/script/merge new file mode 100644 index 0000000..ad7c083 --- /dev/null +++ b/.vim/script/merge @@ -0,0 +1,83 @@ +" Define the function we'll use. It's easier to do this than to faff about +" trying to run a sequence of normal mode commands. +fun! P4merge() + " There should be four arguments: + " 0. The original file (tmp.xxx). + " 1. Their version (tmp.yyy). + " 2. My version (original filename). + " 3. The merged version (tmp.zzz). + + if argc() != 4 + return + endif + + let l:filename = fnameescape(fnamemodify(argv(2), ":h")) + + " Make sure the window is big enough for diffs. + if &columns < 165 + let &columns=(&columns * 2) + endif + + " Mark the buffer for the original file. + set ro + set nomodifiable + set nobuflisted + set buftype=nowrite + set bufhidden=hide + setlocal noswapfile + exe "file \[ORIG:" . l:filename . "\]" + diffthis + 1 + + " Split the buffer for my version. + split +buffer\ 3 + set ro + set nomodifiable + set nobuflisted + set buftype=nowrite + set bufhidden=hide + setlocal noswapfile + exe "file \[YOURS:" . l:filename . "\]" + diffthis + 1 + + " Split the buffer for their version and put it below. + split +buffer\ 2 + wincmd J + set ro + set nomodifiable + set nobuflisted + set buftype=nowrite + set bufhidden=hide + setlocal noswapfile + exe "file \[THEIRS:" . l:filename . "\]" + diffthis + 1 + + " Split the buffer for the merged version and put it at the side. + split +buffer\ 4 + wincmd L + se modifiable + 1 +endfun + +" Expand the command line window so we don't have to press RETURN later. +let s:cmdheight = &cmdheight +set cmdheight=3 + +" Call and then discard our function. +call P4merge() +delfunction P4merge + +" Restore the command window. +exe "set cmdheight=" . s:cmdheight + +" Close the scratch buffer. +if version >= 700 + " Vim 7 lets us close the buffer by number. The merge is always in #4. + au BufWinLeave qa! +else + " Prior versions can only do it by name. Fall back to a temporary file. + au BufWinLeave /tmp/tmp.*.* qa! +endif +