I would like my quickfix-window to have some highlighting for the current line of the cursor.
After some research I found that I could configure the general appearance of the current line using set cursorline
and highlight CursorLine term=bold cterm=bold guibg=Grey40
.
Now, I only want that when I'm in the quickfix-window though. So I started to wrap these 2 lines inside a function and called that function with a autocommand:
au QuickFixCmdPre * call EnableSearchHighlighting()
So far, so good. Since I still have the highlighting activated after I searched at least once, I needed to disable the effect again. And here is where I am stuck...
I wrote another function to just set nocursorline
and call this one on the QuickFixCmdPost
-Event. But for some reason this broke everything. Now I won't get the highlighting anymore, not even in the quickfix-window.
It feels like the Post-Event overrides the Pre-Event. I'm not sure what else to try here.
Maybe anyone can help me out or even has another approach to the highlighting in the first place?
Here is the full code as it is in my .vimrc right now:
function EnableSearchHighlighting()
set cursorline
highlight CursorLine term=bold cterm=bold guibg=Grey40
endfunction
function DisableSearchHighlighting()
set nocursorline
endfunction
au QuickFixCmdPre * call EnableSearchHighlighting()
au QuickFixCmdPost * call DisableSearchHighlighting()
Thanks for reading. :)
Your approach has many problems, but the main one (and the reason it doesn't work) is that both QuickFixCmdPre
and QuickFixCmdPost
are run for each quickfix command before you get to switch to the error window.
Add this to a file ftplugin/qf.vim
:
setlocal cursorline
Then add the highlight
definition to your vimrc
, outside any function or autocmd
:
highlight CursorLine term=bold cterm=bold guibg=Grey40