Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlighting the current line number in vim

Is there a way to highlight only the current line number (in the left hand coloumn) in vim, without highlighting the background of the current line? Ideally, I would Like to make the current line number bold.

like image 729
cg433n Avatar asked Nov 23 '11 18:11

cg433n


People also ask

How do I highlight in vim?

Press 1 to highlight the current visually selected text, or the current word (if nothing is selected). Highlight group hl1 is used. Press 2 for highlight hl2 , 3 for highlight hl3 , etc. Press 0 to remove all highlights from the current visually selected text, or the current word.

How do I enable syntax highlighting in vim?

After opening login.sh file in vim editor, press ESC key and type ':syntax on' to enable syntax highlighting. The file will look like the following image if syntax highlighting is on. Press ESC key and type, “syntax off” to disable syntax highlighting.


2 Answers

You want to look at

:se cursorline 

and perhaps even/also

:se cursorcolumn 
like image 29
sehe Avatar answered Oct 03 '22 10:10

sehe


There are two groups that determine highlighting of line displayed when &cursorline option is active: CursorLine and CursorLineNR. First is used to highlight the whole line, second for the line number. So to achieve what you want you must

  1. Clear the highlighting of CursorLine: just hi clear CursorLine after any :colorscheme and set background= call.

    hi clear CursorLine augroup CLClear     autocmd! ColorScheme * hi clear CursorLine augroup END 
  2. Set the highlighting of CursorLineNR if it is not set in your colorscheme:

    hi CursorLineNR cterm=bold augroup CLNRSet     autocmd! ColorScheme * hi CursorLineNR cterm=bold augroup END 

    (better to check whether it is already set in the colorscheme, maybe it will look better in that case).

You can join both autocommands in one of course.

CursorLineNR has been added relatively recently around version 7.3.488.

like image 133
ZyX Avatar answered Oct 03 '22 10:10

ZyX