Smart choice of vertical or horizontal diff

This commit is contained in:
Tim Pope 2014-06-21 08:18:46 -04:00
parent 0a19a3e78f
commit c5a3c5f8ce
2 changed files with 17 additions and 5 deletions

View File

@ -149,14 +149,16 @@ that are part of Git repositories).
index is used (which means a three-way diff during a index is used (which means a three-way diff during a
merge conflict, making it a git-mergetool merge conflict, making it a git-mergetool
alternative). The newer of the two files is placed alternative). The newer of the two files is placed
to the right. Use |do| and |dp| and write to the to the right or bottom, depending on 'diffopt' and
index file to simulate "git add --patch". the width of the window relative to 'textwidth'. Use
|do| and |dp| and write to the index file to simulate
"git add --patch".
*fugitive-:Gsdiff* *fugitive-:Gsdiff*
:Gsdiff [revision] Like |:Gdiff|, but split horizontally. :Gsdiff [revision] Like |:Gdiff|, but always split horizontally.
*fugitive-:Gvdiff* *fugitive-:Gvdiff*
:Gvdiff [revision] Identical to |:Gdiff|. For symmetry with |:Gsdiff|. :Gvdiff [revision] Like |:Gdiff|, but always split vertically.
*fugitive-:Gmove* *fugitive-:Gmove*
:Gmove {destination} Wrapper around git-mv that renames the buffer :Gmove {destination} Wrapper around git-mv that renames the buffer

View File

@ -1386,7 +1386,7 @@ endfunction
" }}}1 " }}}1
" Gdiff {{{1 " Gdiff {{{1
call s:command("-bang -bar -nargs=* -complete=customlist,s:EditComplete Gdiff :execute s:Diff(<bang>0,<f-args>)") call s:command("-bang -bar -nargs=* -complete=customlist,s:EditComplete Gdiff :execute s:Diff(s:diff_horizontal(),<f-args>)")
call s:command("-bar -nargs=* -complete=customlist,s:EditComplete Gvdiff :execute s:Diff(0,<f-args>)") call s:command("-bar -nargs=* -complete=customlist,s:EditComplete Gvdiff :execute s:Diff(0,<f-args>)")
call s:command("-bar -nargs=* -complete=customlist,s:EditComplete Gsdiff :execute s:Diff(1,<f-args>)") call s:command("-bar -nargs=* -complete=customlist,s:EditComplete Gsdiff :execute s:Diff(1,<f-args>)")
@ -1406,6 +1406,16 @@ augroup fugitive_diff
\ endif \ endif
augroup END augroup END
function! s:diff_horizontal() abort
if &diffopt =~# 'horizontal' && &diffopt !~# 'vertical'
return 1
elseif &diffopt =~# 'vertical'
return 0
else
return winwidth(0) <= 2 * (&tw ? &tw : 80)
endif
endfunction
function! s:diff_window_count() abort function! s:diff_window_count() abort
let c = 0 let c = 0
for nr in range(1,winnr('$')) for nr in range(1,winnr('$'))