Brand New
Brand New

Reputation: 31

How do I put the focus on the QuickFix window after automatically opening the QuickFix list?

I have the following in my .vimrc to automatically open/close the QuickFix window after running :make :

  augroup quickfix
    autocmd!
    autocmd QuickFixCmdPost [^l]* cwindow
    autocmd QuickFixCmdPost l*    lwindow
  augroup END

It works fine, but when the autocmd opens the QuickFix window, it does not put the focus on the window. Is there any way to automatically put the focus on the QuickFix window after the autocmd opens it?

Upvotes: 1

Views: 457

Answers (2)

SergioAraujo
SergioAraujo

Reputation: 11800

I did not have tested the code below yet, but if you can:

augroup quickfix
    autocmd!
    autocmd QuickFixCmdPost [^l]* cwindow | wincmd j
    autocmd QuickFixCmdPost l*    lwindow | wincmd j
augroup END

For more read :h wincmd.

Upvotes: 0

romainl
romainl

Reputation: 196556

From :help :make:

7. If [!] is not given the first error is jumped to.

So…

  • :make jumps to the first error, with or without :cwindow,
  • :make! doesn't jump to the first error so the cursor stays where it is.

NOTE: the same applies to :grep.

Upvotes: 2

Related Questions