From a4de0238bb2d54475ac8ec38b70d4d0a860dbfd1 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Thu, 3 Jan 2019 00:23:02 -0500 Subject: [PATCH] Try split instead of preview window for :G --- autoload/fugitive.vim | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 91c302e..fedc6bc 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -1544,8 +1544,6 @@ function! fugitive#BufReadStatus() abort nnoremap ds :execute StageDiff('Gsdiff') nnoremap dp :execute StageDiffEdit() nnoremap dv :execute StageDiff('Gvdiff') - nnoremap p :echoerr 'Use P' - xnoremap p :echoerr 'Use P' nnoremap P :execute StagePatch(line('.'),line('.')+v:count1-1) xnoremap P :execute StagePatch(line("'<"),line("'>")) nnoremap q :if bufnr('$') == 1quitelsebdeleteendif @@ -1557,6 +1555,7 @@ function! fugitive#BufReadStatus() abort nnoremap X :execute StageDelete(line('.'),v:count) xnoremap X :execute StageDelete(line("'<"),line("'>")-line("'<")+1) nnoremap . : =fnameescape(get(StatusCfile(),0,'')) + nnoremap q :bdelete nnoremap g? :help fugitive-:Gstatus nnoremap :help fugitive-:Gstatus @@ -1890,10 +1889,29 @@ augroup END function! s:Status(bang, count, mods) abort try - exe (a:mods ==# '' ? '' : a:mods) 'Gpedit :' - wincmd P - setlocal foldmethod=syntax foldlevel=1 buftype=nowrite - nnoremap q :bdelete + let dir = b:git_dir + let mods = a:mods ==# '' || empty(a:mods) ? 'leftabove' : a:mods + let file = fugitive#Find(':') + for winnr in range(1, winnr('$')) + if s:cpath(file, fnamemodify(bufname(winbufnr(winnr)), ':p')) + exe winnr . 'wincmd w' + let w:fugitive_status = dir + return s:ReloadStatus() + endif + endfor + let wide = winwidth(0) >= 160 + if a:count ==# 0 + exe mods 'Gedit :' + elseif a:bang + exe mods (a:count ==# -1 && wide ? 'vert' : '') 'Gpedit :' + wincmd P + elseif a:count ==# -1 && wide + exe mods 'Gvsplit :' + else + exe mods a:count > 0 ? a:count : '' 'Gsplit :' + endif + let w:fugitive_status = dir + setlocal foldmethod=syntax foldlevel=1 catch /^fugitive:/ return 'echoerr v:errmsg' endtry @@ -2817,6 +2835,7 @@ endfunction function! s:UsableWin(nr) abort return a:nr && !getwinvar(a:nr, '&previewwindow') && + \ empty(getwinvar(a:nr, 'fugitive_status')) && \ index(['gitrebase', 'gitcommit'], getbufvar(winbufnr(a:nr), '&filetype')) < 0 && \ index(['nofile','help','quickfix'], getbufvar(winbufnr(a:nr), '&buftype')) < 0 endfunction @@ -2840,15 +2859,13 @@ function! s:EditParse(args) abort endfunction function! s:BlurStatus() abort - if &previewwindow && get(b:,'fugitive_type', '') ==# 'index' + if &previewwindow && get(b:,'fugitive_type', '') ==# 'index' || exists('w:fugitive_status') let winnrs = filter([winnr('#')] + range(1, winnr('$')), 's:UsableWin(v:val)') if len(winnrs) exe winnrs[0].'wincmd w' - elseif winnr('$') == 1 - let tabs = (&go =~# 'e' || !has('gui_running')) && &stal && (tabpagenr('$') >= &stal) - execute 'rightbelow' (&lines - &previewheight - &cmdheight - tabs - 1 - !!&laststatus).'new' else - rightbelow new + let wide = winwidth(0) >= 160 + exe 'rightbelow' (winwidth(0) >= 160 ? 'vert' : '') 'new' endif if &diff let mywinnr = winnr()