8

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.

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

2 Answers 2

11

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
1
  • Unfortunately, this doesn't always work for me. See below answer by Kirill Bugaev.
    – Grwlf
    Aug 29, 2019 at 20:16
9

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 you have read our privacy policy.

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