Vim Configure Line Number Coloring

79,933

Solution 1

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

Solution 2

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.

Solution 3

In MacVim (with Vim 7.3 at it's core) I've found CursorLineNr to work:

hi CursorLineNr guifg=#050505

Solution 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
Share:
79,933

Related videos on Youtube

Daniel Spiewak
Author by

Daniel Spiewak

Updated on July 08, 2022

Comments

  • Daniel Spiewak
    Daniel Spiewak almost 2 years

    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.

    • Jgs pra
      Jgs pra about 4 years
      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. jigarpra.blogspot.com/2020/03/…
  • devios1
    devios1 almost 11 years
    Do you happen to have a link to available color names and/or color formats this command supports?
  • nicholsonjf
    nicholsonjf over 10 years
    Thanks, 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
  • Ciro Santilli OurBigBook.com
    Ciro Santilli OurBigBook.com almost 10 years
    This sets the number of the current line only: very useful, but probably not what was required. That was asked at: stackoverflow.com/questions/8247243/…
  • horta
    horta almost 9 years
    7 years later, it appears gVim can handle "grey", but can't handle the number format you describe. :highlight LineNr guifg=grey worked for me.
  • hidden-username
    hidden-username over 8 years
    In 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?
  • qasimalbaqali
    qasimalbaqali over 8 years
    @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.
  • hidden-username
    hidden-username over 8 years
    I figured it out. It is actually set in colorscheme command, so you will have to recall it after updating your colorscheme.
  • IC_
    IC_ over 6 years
    How can change highlight settings for active LineNr? UPD: Answer CursorLineNr
  • dwanderson
    dwanderson over 6 years
    Just 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?
  • ecjb
    ecjb over 4 years
    Thanks 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?
  • Phenyl
    Phenyl almost 4 years
    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.
  • trinaldi
    trinaldi almost 4 years
    @ecjb Did you try putting it after your colorscheme setting?
  • ecjb
    ecjb almost 4 years
    @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
  • trinaldi
    trinaldi almost 4 years
    That's the idea. You should have another setting for the current line/column set, thus this result.