From 8edc9cd0060646cd00de2425178cf82acfccae9e Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Fri, 27 Jul 2018 00:35:27 -0400 Subject: [PATCH] Work around janky autocommands when returning to diffed window Closes https://github.com/tpope/vim-fugitive/issues/1065 --- autoload/fugitive.vim | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index eee8d4c..c3c2b58 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -2116,6 +2116,7 @@ function! s:Diff(vert,keepfocus,...) abort endif let vert = empty(a:vert) ? s:diff_modifier(2) : a:vert let commit = s:DirCommitFile(@%)[1] + let back = exists('*win_getid') ? 'call win_gotoid(' . win_getid() . ')' : 'wincmd p' if exists(':DiffGitCached') return 'DiffGitCached' elseif (empty(args) || args[0] ==# ':') && commit =~# '^[0-1]\=$' && !empty(s:TreeChomp('ls-files', '--unmerged', '--', s:Relative(''))) @@ -2125,12 +2126,12 @@ function! s:Diff(vert,keepfocus,...) abort execute 'nnoremap dp :diffput '.nr.'diffupdate' let nr2 = bufnr('') call s:diffthis() - wincmd p + exe back execute 'rightbelow '.vert.'split' s:fnameescape(s:Generate(s:Relative(':3:'))) execute 'nnoremap dp :diffput '.nr.'diffupdate' let nr3 = bufnr('') call s:diffthis() - wincmd p + exe back call s:diffthis() execute 'nnoremap d2o :diffget '.nr2.'diffupdate' execute 'nnoremap d3o :diffget '.nr3.'diffupdate' @@ -2175,7 +2176,7 @@ function! s:Diff(vert,keepfocus,...) abort let w:fugitive_diff_restore = restore let winnr = winnr() if getwinvar('#', '&diff') - wincmd p + exe back if !a:keepfocus call feedkeys(winnr."\w", 'n') endif