How can I enable 'cursorline' in the preview window?

I use :ptag to show the preview and like that it shows several lines, but for short functions or member lists it's hard to see the line containing my tag. Using cursorline would help.

I tried this:

autocmd WinEnter * if &previewwindow | setlocal cursorline | endif 

The preview window opens without a cursorline (even after C-L or :redraw), but when I switch to it cursorline activates. I want it to work without moving the cursor.

I tried WinNew instead of WinEnter, but that doesn't work at all. I'm not sure why.

1 Answer 1


:h BufWinEnter is the event:

:autocmd! BufWinEnter * if &previewwindow | setlocal cursorline | endif

I guess the discrepancy is because WinEnter is triggered before 'previewwindow' is set. Possibly what's meant by this note in the help:

        Note: For split and tabpage commands the
        WinEnter event is triggered after the split
        or tab command but before the file is loaded.

Thanks to @romainl for the solution!

  • +1 for BufWinEnter and for the explanation of why WinEnter didn't work initially. That being said, sometimes, the event is not fired when a preview window is opened. So, fwiw, I prefer WinLeave.
    – user938271
    Sep 24, 2018 at 18:54

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.