One thing that drives me crazy is unpredictable quickfix behaviour.

Say I am editing a file, then I split the window and would like to find something and open in that buffer.

I use :Ag whatever to fill the QuickFix and press Enter on the search result.


File is opened in the split I use before going to QuickFix.


File is opened in any split on the screen.

Am I missing something?

I know that you can search first and split after. I usually keep many buffers open to see the whole chain of calls/requires and I would like to insert buffers in between other ones.

2 Answers 2


This is a fairly widespread and well-known annoyance. There are at least two plugins which aim to address it: vim-qf and QFEnter

But, the behavior is quite predictable (cf :help quickfix.txt). If the file is already open, vim switches to it and moves to the correct line/column. Otherwise, the window directly above the quickfix window is used (and the buffer is replaced).

So aside from living with the possibly unintuitive default behavior, you have a few options:

  • remap <cr> (or anything else) in the quickfix window to do something else, for example opening the item in the previous window. Example: autocmd FileType qf nnoremap <cr> :exe 'wincmd p \| '.line('.').'cc'<cr>

  • use a plugin which makes similar maps

  • only ever use :cc, :cnext, and :cprev, which operate in the current window (although this would requireset switchbuf=)


Are you using ag.vim which is depecrated? You should try ack.vim.

Other than that, are you sure that the expected window is focused?

I have these settings in my vimrc to make the split direction more "natural":

set splitbelow " Split windows below the current window
set splitright " Split windows right of the current window

Edit: From the quickfix-window help:

The file containing the error is opened in the window above the quickfix window. If there already is a window for that file, it is used instead.

It seems to open the file in the bottom right split every time, not the last used.

  • 1
    Actually I am using vim-grepper. Just kept the same command because it uses ag anyway. The question is how Quickfix decides in which buffer it will open the file?
    – firedev
    Commented Aug 26, 2017 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.