How can set BufEnter or WinEnter autocmds for entering quickfix window?

I tried

autocmd WinEnter quickfix echo 'winenter'
autocmd BufEnter quickfix echo 'bufenter'

None of them works. I doubt that it is because these two commands needs file name after the event name. Then what is the file pattern for quickfix window?

I have fugitive installed. By filling the quickfix window using Glog, the statusline for the quickfix window shows something like [:git --git-dir=...] [Quickfix List]. Is this the filename of the quickfix buffer which should be used in the pattern of the BufEnter/WinEnter event?

I cannot see anything if I echo @% which should usually show the current bufname.

  • autocmd Filetype qf ... may work as well
    – balki
    Jul 20 at 18:32

2 Answers 2


The parameter for both the WinEnter and BufEnter events are matched against the buffer name, which is empty for the quickfix window:

:echo bufname('')
[no output]

You can still use the buftype variable though:

autocmd WinEnter * if &buftype == 'quickfix' | echo 'winenter' | endif
  • Unfortunately, this doesn't always work for me. See below answer by Kirill Bugaev.
    – Grwlf
    Aug 29, 2019 at 20:16

Just a remark to Martin Tournoij answer.

When you just opened a quickfix buffer/window (and not switched to it yet), the &buftype option is not set yet. You may find another autocommand event useful:

autocmd BufWinEnter quickfix echo 'bufwinenter'

Your Answer

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

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