I've been struggling with that behavior for a long time.
Basically, the foreground color of SpecialKey on the current line is changed to the foreground color of Normal if:
the cursorline option is enabled,
the CursorLine highlight group has a background color set.
I've never been able to fix that behavior, no matter what I tried. The problem lies ...
Patch 8.0.0641 introduced a separate highlight group for the quickfix line, called QuickFixLine. With patch 8.0.0653 this group is linked to the Search highlight by default, because for some color schemes the colors chosen for patch 8.0.0641 did not work well.
So if you have a current version of Vim you can use
hi QuickFixLine cterm=None ctermbg=256 guibg=#...
One would expect, that the OptionSet autocommand is triggered when entering diff mode. Unfortunately that is currently not the case. So I created a patch that will enable this behavior. Once it is merged, you can basically do this:
au OptionSet diff let &cul=!v:option_new
As a workaround, currently you have to do something like this:
You need these three lines:
hi CursorLineNr guifg=#af00af
The last line removes the highlighting of the cursor line even if cursorline is set and only highlights the cursor line number.
As you can see from the output of :verbose :hi CursorLine, your CursorLine setting is reset by the colorscheme you are using.
There are a couple of approaches you can use to change that.
Simply comment out the line in the colorscheme.
Use a VimEnter autocommand, to have your configuration setting set after Vim has startup:
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
wincmd p " go to original window
wincmd p " back to quickfix window
The ftplugin files are executed ...
What worked for me was the following lines in my .vimrc (based on Igor Mikushkin's answer).
autocmd BufNewFile,BufRead * call matchadd('SpecialKey', '\s\+')
autocmd BufNewFile,BufRead * call matchadd('NonText', '\n\+')
VimEnter only works for the first file you open, not for files/tabs you open afterwards. BufNewFile,BufRead has worked so far for all the ...
As @Christian Brabandt pointed out in the comment this is a known issue and there might not be a lot of solutions, for now, to make cursorline work properly.
However, you can use different workarounds:
In this answer @Carpetsmoker suggest a mapping which will set cursorline and cursorcolumn for a fraction of a second. This is pretty useful to easily locate ...
: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 ...
What works for me, in your .vimrc first set your colorscheme, then your desired highlight:
highlight Cursorline whatever_you_like
That way your colorscheme won't clobber your highlight.
The style of these two settings is defined by the CursorLine and CursorColumn highlight groups.
If I query these two on my Vim, I get:
CursorColumn xxx term=reverse ctermbg=242 guibg=Grey40
CursorLine xxx term=underline cterm=underline
So what we want to do is make CursorLine look more ...
Your example is trying to mimic popup menu by popup window, it's complicate, I changed it to use arrow keys to scroll popup window in normal mode, it's only purpose is to show you how to change cursor in popup window:
noremap <buffer> <down> :call Omni_cursor(1)<CR>
noremap <buffer> <up> :call Omni_cursor(0)<CR>
I actually went with coloring the background of the line number. This way you're not interfering with syntax colors or underscores.
So basically I have this (for light background terminal)
highlight CursorLineNr ctermfg=white guifg=white ctermbg=darkgrey guibg=darkgrey cterm=bold gui=bold
The CursorLine highlighting group defines how the current line will be highlighted, once :set cursorline is enabled. As you have noticed, it contains an option for setting the background color.
If you do not want that and basically just want the underlining to take place, I would suggest to change the highlighting group to:
:hi CursorLine cterm=underline ...
This is not possible as of today. The reason most likely is, that the non-highlighted indented part is actually only a representation and does not really exist in the file. I am not sure it makes sense, to color that for the cursorline.
For reference, this question has made it to a Vim Ticket: #3355
Try the following two commands:
" Match when cursor before column
matchadd('ColorColumn', '\%#.*\zs\%81v', 100)
" Match when cursor after column
matchadd('ColorColumn', '\%81v\ze.*\%#', 100)
It should be possible to combine these into a single regular expression, but simply placing them into an alternation with \| doesn't work correctly*, so doing so ...
currently I solved it this way (though I would be very grateful if someone suggested a better way).
I created a syntax highlihgt file for the qf syntax ~/.vim/after/syntax/qf.vim. There I defined:
hi Search cterm=none ctermbg=226 guibg=#ffff00
This disabled the cursor line highlighting in the quickfix window (which is tolerable for ...
Following lines in .vimrc fixed the problem for me.
au VimEnter * call matchadd('SpecialKey', '^\s\+', -1)
au VimEnter * call matchadd('SpecialKey', '\s\+$', -1)
It overrides other styles application for tabs and trailing spaces inside a cursor line.