diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index 2ce77cc..68ca819 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -1386,9 +1386,9 @@ endfunction " }}}1 " Gdiff {{{1 -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,)") +call s:command("-bang -bar -nargs=* -complete=customlist,s:EditComplete Gdiff :execute s:Diff('',)") +call s:command("-bar -nargs=* -complete=customlist,s:EditComplete Gvdiff :execute s:Diff('vert ',)") +call s:command("-bar -nargs=* -complete=customlist,s:EditComplete Gsdiff :execute s:Diff(' ',)") augroup fugitive_diff autocmd! @@ -1406,14 +1406,14 @@ augroup fugitive_diff \ endif augroup END -function! s:diff_horizontal() abort +function! s:diff_horizontal(count) abort if &diffopt =~# 'horizontal' && &diffopt !~# 'vertical' - return 1 + return 'vert ' elseif &diffopt =~# 'vertical' - return 0 + return ' ' else let fdc = matchstr(&diffopt, 'foldcolumn:\zs\d\+') - return winwidth(0) <= 2 * ((&tw ? &tw : 80) + (empty(fdc) ? 2 : fdc)) + return winwidth(0) <= a:count * ((&tw ? &tw : 80) + (empty(fdc) ? 2 : fdc)) ? ' ' : 'vert ' endif endfunction @@ -1491,11 +1491,12 @@ endfunction call s:add_methods('buffer',['compare_age']) -function! s:Diff(bang,...) abort - let vert = a:bang ? '' : 'vertical ' +function! s:Diff(vert,...) abort + let vert = empty(a:vert) ? s:diff_horizontal(2) : a:vert if exists(':DiffGitCached') return 'DiffGitCached' elseif (!a:0 || a:1 == ':') && s:buffer().commit() =~# '^[0-1]\=$' && s:repo().git_chomp_in_tree('ls-files', '--unmerged', '--', s:buffer().path()) !=# '' + let vert = empty(a:vert) ? s:diff_horizontal(3) : a:vert let nr = bufnr('') execute 'leftabove '.vert.'split `=fugitive#buffer().repo().translate(s:buffer().expand('':2''))`' execute 'nnoremap dp :diffput '.nr.'diffupdate'