From 28d4eca569c2cea87759fb089e1c9a19c954c92b Mon Sep 17 00:00:00 2001 From: Quinn Strahl Date: Sat, 7 Sep 2019 15:18:28 -0400 Subject: [PATCH 1/3] Use getqflist() on QuickFixCmdPre to decide which list to open Some plugins - for example, tpope's fugitive - trigger custom QuickFixCmdPost events using :doautocmd. This causes some commands - for example, :Glgrep - to trigger inappropriate calls to qf#OpenQuickfix when they should be triggering qf#OpenLoclist, due to the way qf.vim determines which list to open (by command name). To solve this, we can cache the value of getqflist() on QuickFixCmdPre, and check it again on QuickFixCmdPost. If the value has changed, we know to call qf#OpenQuickfix. Otherwise, we call qf#OpenLoclist. This should allow for seamless integration with these sorts of plugin commands, without having to know or care about their names. --- plugin/qf.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/qf.vim b/plugin/qf.vim index a876262..730e198 100644 --- a/plugin/qf.vim +++ b/plugin/qf.vim @@ -61,9 +61,9 @@ augroup qf " automatically open the location/quickfix window after :make, :grep, " :lvimgrep and friends if there are valid locations/errors - autocmd QuickFixCmdPost [^l]* nested call qf#OpenQuickfix() - autocmd QuickFixCmdPost l* nested call qf#OpenLoclist() - autocmd VimEnter * nested call qf#OpenQuickfix() + autocmd QuickFixCmdPre * nested let s:qflist = getqflist() + autocmd QuickFixCmdPost * nested exe 'call qf#Open' . (s:qflist == getqflist() ? 'Loclist' : 'Quickfix') . '()' + autocmd VimEnter * nested call qf#OpenQuickfix() " automatically close corresponding loclist when quitting a window if exists('##QuitPre') From cb7d41a0df9ea233802efe779bab402872c203c9 Mon Sep 17 00:00:00 2001 From: Quinn Strahl Date: Sat, 7 Sep 2019 23:41:16 -0400 Subject: [PATCH 2/3] Map in quickfix windows to use previous window --- after/ftplugin/qf.vim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/after/ftplugin/qf.vim b/after/ftplugin/qf.vim index 67bc058..73742cf 100644 --- a/after/ftplugin/qf.vim +++ b/after/ftplugin/qf.vim @@ -136,6 +136,11 @@ nnoremap :call qf#history#Newer() nnoremap } :call qf#filegroup#NextFile() nnoremap { :call qf#filegroup#PreviousFile() +if !b:qf_isLoc + nnoremap ':wincmd p '.line('.').'cc' + let b:undo_ftplugin .= "| execute 'nunmap '" +endif + " quit Vim if the last window is a quickfix window autocmd qf BufEnter nested if get(g:, 'qf_auto_quit', 1) | if winnr('$') < 2 | q | endif | endif autocmd qf BufWinEnter nested if get(g:, 'qf_auto_quit', 1) | call qf#filter#ReuseTitle() | endif From 495c4b652bb08716367389ab740f8e3179926386 Mon Sep 17 00:00:00 2001 From: Quinn Strahl Date: Sat, 7 Sep 2019 23:42:27 -0400 Subject: [PATCH 3/3] Stop vim from jumping to the last window on QuickFixCmdPost --- plugin/qf.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugin/qf.vim b/plugin/qf.vim index 730e198..da4d431 100644 --- a/plugin/qf.vim +++ b/plugin/qf.vim @@ -65,6 +65,10 @@ augroup qf autocmd QuickFixCmdPost * nested exe 'call qf#Open' . (s:qflist == getqflist() ? 'Loclist' : 'Quickfix') . '()' autocmd VimEnter * nested call qf#OpenQuickfix() + " stop vim from jumping to the last window before opening the first entry + autocmd QuickFixCmdPre * nested let s:winnr = winnr() + autocmd QuickFixCmdPost * nested exe s:winnr 'wincmd w' + " automatically close corresponding loclist when quitting a window if exists('##QuitPre') autocmd QuitPre * nested if &filetype != 'qf' | silent! lclose | endif