How do I highlight only the line number of the current line without highlighting the entire line?
Answer
:set cursorlineopt=number
Explanation
When cursorline is enabled, Vim highlights the entire line the cursor is on. In dense code, this full-line highlight can be visually overwhelming. Setting cursorlineopt=number limits the highlight to just the line number column — giving you a clear cursor position indicator without washing out the whole line.
How it works
cursorlineopt controls which parts of the current line are highlighted when cursorline is active (Vim 8.2+ and Neovim):
| Value | Effect |
|---|---|
line |
Entire line is highlighted (default) |
number |
Only the line number in the gutter |
screenline |
Only the physical screen line (relevant with wrap) |
both |
Line number + full line |
number,line |
Combines values (same as both) |
Requires both set cursorline and set number (or set relativenumber) to be visible.
Example
Add to your config:
set cursorline
set number
set cursorlineopt=number
Result: the number column highlights the current line's number in CursorLineNr color, while the text of the line remains unhighlighted — subtle but effective.
Tips
- Combine with a distinct
CursorLineNrhighlight for maximum visibility::hi CursorLineNr guifg=#ffdd44 gui=bold cursorlineopt=numberpairs well withrelativenumberso both the absolute number and relative offsets are highlighted- Use
cursorlineopt=line,numberif you want both effects simultaneously - The
screenlinevalue is useful whenwrapis on and a single logical line spans multiple screen rows