Due to performance, I disable the cursorline and cursorcolumn in Vim. However, in the case jumping through a Quickfix window, it is hard to locate the cursor in the file. So I would like to enable cursorline and cursorcolumn automatically after a Quickfix window is opened (by whatever actions).

Now I have the solution using the Autocmd like this:

autocmd BufferEnter quickfix :bufdo set cursorline cursorcolumn

Is this the proper solution? Any better idea?

Thanks very much!

  • 2
    Maybe you could use the event QuickFixCmdPost (:h QuickFixCmdPost) instead but I'm not sure that would be better.
    – statox
    Dec 28, 2016 at 14:34
  • @statox Thanks, it works with Ack, vimgrep and so on. But it doesn't work in the case of :copen. Quite nice solution!
    – tamlok
    Dec 29, 2016 at 1:59
  • See :h QuickFixCmdPre it contains a list of the commands triggering the event QuickFixCmdPre (and thus the event QuickFixCmdPost) and indeed :copen is not one of them. So the behavior you're experiencing is normal but I don't know how to make it work with :copen...
    – statox
    Dec 29, 2016 at 9:07

1 Answer 1


Create the file in ~/.vim/ftplugin/qf.vim (or $HOME/vimfiles/ftplugin/qf.vim if you are on Windows) with the following contents:

" Only do this when not done yet for this buffer
if exists("b:did_ftplugin")

wincmd p " go to original window
set cursorline
set cursorcolumn
wincmd p " back to quickfix window

The ftplugin files are executed whenever the filetype is set for a given file buffer (quickfix and location window has the filetyp qf).

Using the filetype plugin files instead of autocmds avoids cluttering your vimrc. You can find more details at :help ftplugin-name, :help 43 and Vim FAQ 26.8.


The check on b:did_ftplugin is necessary to allow disabling it if necessary and to avoid loading it twice (see :help ftplugin).

The let b:did_ftplugin = 1 is omitted from this file because the intent of this file is to increment the default filetype plugin for quickfix, and not override. If this line was added then the settings at $VIMRUNTIME/ftplugin/qf.vim would be skipped, as explained at :help ftplugin-overrule.

  • Thanks very much! But What does b:did_ftplugin mean? Your script seems to not change it anywhere. I have tried it in my vimrc and It works!
    – tamlok
    Dec 30, 2016 at 5:06
  • @tamlok glad I could help. Note that you are not supposed to copy that to your vimrc, but to a file as mentioned in the first phrase. Vim handles that kind of file in a special manner. I updated the question about the b:did_ftpluginpart.
    – mMontu
    Dec 30, 2016 at 10:41

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.