2
votes

In vim, I want to:

  • highlight a single line (e.g. :hi CursorLine ctermbg=black)

AND

  • maintain syntax highlighting

AND

  • not set up any custom color themes or similar

(note: adding a few lines to .vimrc is fine)


I've tried setting via :hi CursorLine ctermbg=black, but this results in changing the cursor highlight color but not maintaining syntax coloring.

not highlighted, and has syntax coloring:

not highlighted but syntax

highlighted, but loses syntax coloring:

highlighted and no syntax

in above example, I would want the string word to stay purple, if word stay yellow, etc., even though line is highlighted.


I also tried toggling :syntax off :syntax on, and not surprisingly this had no effect.


This question (Syntax highlighting in vim) seems similar to what I'm asking, but it's not because 1) I don't want to change the background, 2) I don't want to change theme, 3) it seems like OP here was having trouble with existing syntax color scheme and just wanted to be able to see things.

This question (Custom syntax coloring vim) seems similar to what I'm asking, but it's not because 1) I don't want to change existing syntax coloring, I want to keep it, 2) I don't want to add arbitrary syntax highlighting, I just want CursorLine to be highlighted while also maintaining syntax coloring.

2
Can't reproduce this... What does Vim tell you when you check the highlight configuration with :hi CursorLine? Are the other attributes cleared? If not, you can clear them by setting them to NONE, e.g. :hi CursorLine ctermfg=NONE. Or if you have cterm=reverse then you're actually setting the foreground color with ctermbg... Reset that with cterm=NONE too. - filbranden
@filbranden I ran :hi CursorLine and got CursorLine xxx term=underline cterm=underline guibg=Grey40. I then solved this by doing :hi CursorLine ctermbg=black term=none cterm=none. Not exactly what you said, but that pointed me in the right direction, so thanks! - superswellsam

2 Answers

3
votes

I got my desired behavior by running :hi CursorLine ctermbg=black term=none cterm=none.

And while out of scope of my original question, running :set cursorline is also needed for the line highlighting to be displayed.

0
votes

This seemed to work for me ...

:hi CursorLine cterm=NONE guifg=NONE