8

I routinely have 4 windows, split into a 2x2 grid. When I run a command that populates the quickfix, the first matching location is opened in the current window. But if I choose a QF location that isn't already loaded, it always seems to open in bottom-right-hand window.

Is there a way to make it load in a different window? Specifically, is there a way to make it load in the last window I was in - i.e. the window that "CTRL-w p" would take me to?

3 Answers 3

11

Take a look at QFEnter vim plugin. It opens a item in the 'wincmd p' window when hitting enter or double-clicking on the quickfix item. Actually, it's my plugin :)

1
  • Just downloaded the plugin. Perfect. Simply opens the window in the last focused pane. All I needed, because I generally use 2 vertical panes side-by-side for comparing code. May 25, 2019 at 15:23
4

set switchbuf+=uselast

if you want to load the quickfix item into the previously used window.

3
  • This is the better answer since it doesn't require a plugin. :help switchbuf also specifically states that it only affects quickfix and buffer related split commands, which is great because it is a low-impact change.
    – Kevin
    Apr 6, 2020 at 1:56
  • Side note, why the +=? Why would you want to append this option instead of just doing set switchbuf=uselast?
    – Kevin
    Apr 6, 2020 at 1:58
  • 1
    This requires a fairly new version of Vim; it would be newer than 8.1.2269, which is what's in (e.g.) Ubuntu 20.04 LTS. I haven't been able to figure out exactly which release first included it, but the commit is at github.com/vim/vim/pull/1652/commits/…. Oct 4, 2020 at 17:06
2

From :help quickfix.txt:

In the quickfix window, each line is one error. The line number is equal to the error number. You can use ":.cc" to jump to the error under the cursor. Hitting the key or double-clicking the mouse on a line has the same effect. 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. If the buffer in the used window has changed, and the error is in another file, jumping to the error will fail. You will first have to make sure the window contains a buffer which can be abandoned.

I don't think you'll be able to avoid creating a custom mapping.

1
  • Thanks for the info. I guess I can first switch to the window I want, then use BufExplorer to choose the buffer that quickfix loaded in the window I didn't want.
    – Kelvin
    Aug 16, 2013 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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