I'm looking for a way to configure the color used for line numbering (as in: :set nu
) in Vim. The default on most platforms seems to be yellow (which is also used for some highlighted tokens). I would like to color the line numbers a dim gray; somewhere in the vicinity of #555
. I'm not picky though, any subdued color would be acceptable.
Asked
Active
Viewed 9.0k times
115

Daniel Spiewak
- 54,515
- 14
- 108
- 120
-
If you want to keep constant your desire preference of color scheme background for permanent in vim and if you want to set numbering to it as well, then it's so easy, go through the link provided below and follow the steps which are so easy to do. https://jigarpra.blogspot.com/2020/03/hello-everyone-today-i-will-explain-to.html – Jgs pra Mar 20 '20 at 06:09
4 Answers
173
Try:
help hl-LineNr
I found this through:
help 'number'
which is the way to get help on the 'number'
option, instead of the :number
command.
To actually change the displayed colour:
:highlight LineNr ctermfg=grey
This would change the foreground colour for LineNr on a character terminal to grey. If you are using gVim, you can:
:highlight LineNr guifg=#050505

Greg Hewgill
- 951,095
- 183
- 1,149
- 1,285
-
1Do you happen to have a link to available color names and/or color formats this command supports? – devios1 Jul 16 '13 at 20:44
-
4Thanks, this worked for me. Adding 'set number' and 'highlight LineNr ctermfg=grey' on separate lines at the end of my ~/.vimrc file on Ubuntu 12.04 enabled grey line numbers anytime I open a file with vim – nicholsonjf Dec 29 '13 at 00:19
-
27 years later, it appears gVim can handle "grey", but can't handle the number format you describe. :highlight LineNr guifg=grey worked for me. – horta Jul 23 '15 at 14:23
-
3How can change highlight settings for active `LineNr`? UPD: Answer `CursorLineNr` – IC_ Sep 30 '17 at 06:00
-
1Thanks for the answer. The command `:highlight LineNr ctermfg=grey` works for me, however adding `highlight LineNr ctermfg=grey` in the `~/.vimrc` file doesn't change anything. Does somebody have an idea? – ecjb Jan 25 '20 at 08:38
-
-
@Tico thank you for your comment. Yes now it's after the scheme: the current line number is bright and the other are less bright – ecjb Jun 24 '20 at 18:26
-
That's the idea. You should have another setting for the current line/column set, thus this result. – trinaldi Jun 24 '20 at 22:28
47
To change the line numbers permanently add the below to your .vimrc
highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE
Of course you change the ctermfg
and guifg
to whatever color you want.

qasimalbaqali
- 2,079
- 24
- 51
-
1In order to get the accepted answer to work in my .vimrc I had to follow your advice and add it to the bottom. Can you explain why it has to be at the bottom? – hidden-username Oct 11 '15 at 16:14
-
@mikeyprog I don't really know why, since I found the answer online, but I guess so it overrides the default settings. Since it would read the settings from top to bottom. – qasimalbaqali Oct 11 '15 at 18:12
-
I figured it out. It is actually set in colorscheme command, so you will have to recall it after updating your colorscheme. – hidden-username Oct 12 '15 at 12:25
-
1Just ran into same issue as @hidden-username - and just realized it's because I set themes and colors and etc in the middle of my `vimrc`. So... having this at the top, it got overridden. Overwritten. Overrode? – dwanderson Oct 21 '17 at 00:48
-
In my experience, the `highlight` statement has to come after `syntax on` and `colorscheme` otherwise it's overwritten by the default values of the syntax highlighting. – Phenyl May 19 '20 at 11:44
17
In MacVim (with Vim 7.3 at it's core) I've found CursorLineNr
to work:
hi CursorLineNr guifg=#050505

Roshambo
- 2,692
- 1
- 27
- 24
-
3This sets the number of the current line only: very useful, but probably not what was required. That was asked at: http://stackoverflow.com/questions/8247243/highlighting-the-current-line-number-in-vim – Ciro Santilli OurBigBook.com May 27 '14 at 18:05
4
I didn't like the colors provided by the selected color scheme so I modified the color of the line numbers this way:
colorscheme trivial256 " for light background
hi LineNr term=bold cterm=bold ctermfg=2 guifg=Grey guibg=Grey90

Jabba
- 19,598
- 6
- 52
- 45