5

Background and problem

I've just discovered how to make the cursor a vertical line in insert mode. This works well with cursorline; even with the thinner cursor, I can still easily find my position.

autocmd InsertEnter * set cul
autocmd InsertLeave * set nocul

However, the default underline makes it hard to see literal underscore characters _.

Attempts

  1. I know I can change the highlighting of CursorLine, which would make underscores visible again, but this breaks syntax highlighting.
  2. Another option is to highlight the underscore character itself in Insert mode. However, this seems like overkill, because I don't want every single underscore highlighted. Also, it doesn't work for areas that are syntax highlighted.
syn match underscore "_"
autocmd InsertEnter * hi underscore ctermbg=grey cterm=none ctermfg=black
autocmd InsertLeave * hi clear underscore
  1. I also know that I can change the cursorline to bold, italics, etc., but this is also visual overkill.

  2. An ideal solution would be to make the cursorline underline be a light colour, with the literal underscore a darker black, but it seems that cursorline always inherits ctermfg.

Is there a simple way to still see underscores, while using cursorline?

I'm using regular terminal vim (in Terminator generally), not gvim.

18
  • Have the cursor blink? Perhaps conditional on the line containing underscores?
    – B Layer
    Jun 20, 2019 at 3:39
  • Do you mean instead of using cursorline? I'm not a big fan of blinking things generally from a UX perspective. You have to wait half a cycle before anything is clear.
    – Sparhawk
    Jun 20, 2019 at 3:41
  • No offense but you've ruled out an awful lot of options. ;)
    – B Layer
    Jun 20, 2019 at 3:42
  • See if you can get any ideas from :h 'gcr'.
    – B Layer
    Jun 20, 2019 at 3:44
  • 1
    Thanks for your help @BLayer
    – Sparhawk
    Jun 20, 2019 at 5:40

2 Answers 2

1

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
2
  • Not a bad option (+1), although this bug breaks it, but obviously it would be ideal if the whole line could be highlighted instead.
    – Sparhawk
    Jul 20, 2020 at 2:44
  • To complete this answer, you also need to turn off normal cursorline highlighting, e.g. with highlight CursorLine ctermbg=NONE ctermfg=NONE guibg=NONE guifg=NONE gui=NONE cterm=NONE, and enable highlighting at all with set cursorline.
    – Sparhawk
    Jul 20, 2020 at 4:12
0

I think putting the underline at the line above the CursorLine is perfect (though I can't find such a solution)

My currenct setting:

let g:rice_white_wf='#fdf6e3'

set cursorline
hi CursorLine gui=bold guifg=none guibg=none

    " hi CursorLine guibg=rice_white_wf gui=undercurl
    " syn match underscore "_"
    " hi underscore gui=reverse
hi Visual  guifg=rice_white_wf guibg=#dde6d3 gui=bold     

effect (use bold instead of underline for cursorline)

enter image description here

1
  • 1
    This answer would benefit from an edit explaining how it solves the problem. As written, the code block doesn't give a lot of insight into the problem or solution.
    – D. Ben Knoble
    Jan 26, 2022 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.