2

my usual setup is two vertically split windows. Lets say my cursor is in left window. When I vimgrep something, I would like for quickfix window to reuse already opened right window and automatically open there as a new buffer. Similary, if cursor was in right window, quickfix should open in existing left window. Is that possible? This is what I currently have. But it will open third window that I will have to close later. Thanks.

augroup quickfix
    autocmd!
    autocmd QuickFixCmdPost [^l]* call OpenQuickFixList()
augroup END

"open in vertical split and realign windows
function OpenQuickFixList()
    vert cwindow
    execute "normal \<C-w>="
endfunction
2
  • Note that the linked question asks for sort of the opposite of what you’re asking. You’ll need to tweak my answer there slightly to open the quickfix in the other window. Happy to give tips on how to do this if you get stuck.
    – Rich
    Commented Nov 1, 2019 at 14:55
  • Looks funny when @Rich states linked question asks the opposite and then this one is marked as duplicate. I myself feel a bit frustrated, this is the second question I give answer to spending 15-20 minutes that then is marked as duplicate. I should probably have a strategy to not answer recent questions and wait 24 hours first :)
    – Maxim Kim
    Commented Nov 1, 2019 at 17:28

1 Answer 1

2

if you want to always have it opened in vertical split with your current window, try next function:

augroup quickfix
    autocmd!
    autocmd QuickFixCmdPost [^l]* call OpenQuickFixList()
augroup END

function OpenQuickFixList()
    wincmd o
    vert cwindow
    wincmd p
    wincmd =
endfunction

What it does is

  1. make current window the only one (:h wincmd)
  2. vertically split cwindow
  3. goes to previous window (remove this line if you want to stay in quickfix)
  4. make windows equal

PS

enter image description here

2
  • 2
    Note that the side effects of wincmd o include, well, closing any other open windows I had. The dupe-target (see comments) has a better, less intrusive way to achieve this
    – D. Ben Knoble
    Commented Nov 1, 2019 at 14:52
  • 1
    Indeed, but it was as OP described ;) “is two vertical spit windows”
    – Maxim Kim
    Commented Nov 1, 2019 at 16:23

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