From c5a3c5f8ce539a23e4ad14a6cdd9461ade79b748 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sat, 21 Jun 2014 08:18:46 -0400 Subject: [PATCH] Smart choice of vertical or horizontal diff --- doc/fugitive.txt | 10 ++++++---- plugin/fugitive.vim | 12 +++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/doc/fugitive.txt b/doc/fugitive.txt index 6397209..5e0a3a4 100644 --- a/doc/fugitive.txt +++ b/doc/fugitive.txt @@ -149,14 +149,16 @@ that are part of Git repositories). index is used (which means a three-way diff during a merge conflict, making it a git-mergetool alternative). The newer of the two files is placed - to the right. Use |do| and |dp| and write to the - index file to simulate "git add --patch". + to the right or bottom, depending on 'diffopt' and + 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* -:Gsdiff [revision] Like |:Gdiff|, but split horizontally. +:Gsdiff [revision] Like |:Gdiff|, but always split horizontally. *fugitive-:Gvdiff* -:Gvdiff [revision] Identical to |:Gdiff|. For symmetry with |:Gsdiff|. +:Gvdiff [revision] Like |:Gdiff|, but always split vertically. *fugitive-:Gmove* :Gmove {destination} Wrapper around git-mv that renames the buffer diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index cbb7b71..4d0edd1 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -1386,7 +1386,7 @@ endfunction " }}}1 " Gdiff {{{1 -call s:command("-bang -bar -nargs=* -complete=customlist,s:EditComplete Gdiff :execute s:Diff(0,)") +call s:command("-bang -bar -nargs=* -complete=customlist,s:EditComplete Gdiff :execute s:Diff(s:diff_horizontal(),)") call s:command("-bar -nargs=* -complete=customlist,s:EditComplete Gvdiff :execute s:Diff(0,)") call s:command("-bar -nargs=* -complete=customlist,s:EditComplete Gsdiff :execute s:Diff(1,)") @@ -1406,6 +1406,16 @@ augroup fugitive_diff \ endif 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 let c = 0 for nr in range(1,winnr('$'))