Search code examples
luaconfigurationneovimline-numbers

Need to change the colour of line numbers in neovim


my current line number colors

1

I like to have a very visible line number coloring and I couldn't find a way to configure it in v0.8.2 of Neovim. I'm using tokionight-night as my color theme and would like to have more visible colors on the relative line numbers if possible i'd like to have the side above zero colored blue zero could be yellow/red and below zero pink. I'd like to change it to anything honestly I'm trying to move from vscode, where I changed my colors of line numbers to yellow and I enjoy the visibility very much.

I tried to make it work through this disscussion I've found https://stackoverflow.com/questions/237289/vim-configure-line-number-coloring, with no luck. I haven't found a way to do it in a .lua configuration file and pasting :highlight LineNr ctermfg=grey was no luck either.


Solution

  • Solution: This is a solution that worked for me (Using relative numbers):

    -- Sets colors to line numbers Above, Current and Below  in this order
    function LineNumberColors()
        vim.api.nvim_set_hl(0, 'LineNrAbove', { fg='#51B3EC', bold=true })
        vim.api.nvim_set_hl(0, 'LineNr', { fg='white', bold=true })
        vim.api.nvim_set_hl(0, 'LineNrBelow', { fg='#FB508F', bold=true })
    end
    

    Calling this function in colors.lua right after a function for my neovim theme.

    Like so:

    SetTheme()
    LineNumberColors()