CursorLine highlight in ViM, highlight only line number and spaces / tabs at start / end of line
I am using ViM: Highlight CursorLine to change bg color on current line. But sometimes the text is unreadable.
I would like to highlight, which can only change the background color for the entire line except text (counting spaces / tabs between characters as text).
Is it doable? If so, how?
a source to share
As I know, there can be no direct support for setting how the cursor line is selected.
But I have a trick for what you want. That is, by highlighting the cursor line, we can change the color settings of the titles / trailing spaces in the line as the current "background" and "foreground".
:match NoHighLight /^\s\+|\s\+$/
:highlight NoHighLight guibg=background guifg=foreground
The obvious disadvantage is that the portion from "end of line" to "vim window border" will still be colored as the line customization color. If this is ugly for you, you can simply change the cursor highlight setting by setting only its guifg, like:
:highlight CursorLine guifg=red guibg=background
There may be other neat solutions out there, but I can do it now. :)
Hope it helps.
a source to share
I found a solution -
Regarding @ Zhaojun's answer: this is not what I wanted (also /^\s\+|\s\+$/
not much, maybe it should be /^\s\+\|\s\+$/
)
The solution I found is just a color for the elflord's color scheme.
:highlight CursorLine gui=none guibg=grey10
:set CursorLine
:highlight NoHighLight guibg=background
:match NoHighLight /\S\+\(\s\+\|$\)/
it however doesn't work well for trailing whitespace at the end of the line, but I usually remove them
to make them visible i use the following
:highlight EndSpaces guibg=green
:match EndSpaces /\s\+$/
a source to share