I want the cursor line number to have a different color than the rest of numbers when cursorline is disabled.

The highlight CursorLineNR is only active when set cursorline is set. I could do set cursorline followed by hi clear CursorLine with hi CursorLineNR, however I want cursorline to be visible when sit is set and not visible when it is not set, and still have the cursor line number have a different color.

With set cursorline + hi CursorLineNr guifg=#af00af, the line number 197 is purple:

enter image description here

But when followed by set nocursorline the number 197 is gray as rest of numbers like below.

enter image description here

I want the 197 number to always be purple guifg=#af00af, even after set nocursorline. Is this anyhow possible?

I.e. compare:

vim -u NONE -c 'hi CursorLineNr guibg=#ff0000 ctermbg=red' -c 'set number relativenumber' -c 'exe "normal i\<cr>- should be red\<cr>\<up>\<esc>"' -c 'set nocursorline'

versus the same command line, but change nocursorline on last argument to cursorline and compare. The above command when run with neovim makes the number line in red in both cases.

  • 1
    CursorLineNr Like LineNr when 'cursorline' is set and 'cursorlineopt' is set to "number" or "both", or 'relativenumber' is set, for the cursor line. --should be used when rnu is set no matter what? Having said that, my vim does what yours does. Perhaps a bug? Or perhaps the wordings means ('cul') & ('cursorlineopt' | 'rnu')
    – D. Ben Knoble
    Commented Nov 11, 2020 at 21:29

1 Answer 1


You need these three lines:

hi CursorLineNr guifg=#af00af
set cursorline
set cursorlineopt=number

The last line removes the highlighting of the cursor line even if cursorline is set and only highlights the cursor line number.

  • 1
    Very nice, note, this needs at least 8.1.2019 I believe Commented Nov 12, 2020 at 8:58
  • 1
    @ChristianBrabandt Yes, and 8.1.2155 if it's to be used in a terminal window (which is probably not the case here). Commented Nov 12, 2020 at 9:03

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.