Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In vim, how to highlight a line while keeping syntax coloring?

Tags:

vim

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.

like image 580
superswellsam Avatar asked Oct 28 '25 16:10

superswellsam


1 Answers

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.

like image 54
superswellsam Avatar answered Oct 31 '25 12:10

superswellsam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!