Need to change the colour of line numbers in neovim
Asked Answered
H

5

5

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://mcmap.net/q/186843/-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.

Handcart answered 29/1, 2023 at 19:56 Comment(0)
H
5

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()
Handcart answered 31/1, 2023 at 20:41 Comment(0)
P
2

You can use vim.api.nvim_set_hl() for this.

vim.api.nvim_set_hl(0, 'LineNrAbove', { fg='blue' })
vim.api.nvim_set_hl(0, 'LineNr', { fg='yellow' })
vim.api.nvim_set_hl(0, 'LineNrBelow', { fg='magenta' })

These need to be set after you set your colourscheme for them to not be immediately overwritten.

If you have cursorline enabled, LineNr should be replaced with CursorLineNr.

Proa answered 30/1, 2023 at 17:30 Comment(4)
Wow Thanks this is basically it only CursorLineNr didn't work so I tried LineNr, which turned out to be it.Handcart
Yep, looks like CursorLineNr is only used when you have cursorline enabled.Proa
Straight to the point. Thank youFortepiano
This worked for me by setting Above and Below as grey. Otherwise I weirdly didn't seem to get the yellow in this example.Martinet
G
2

If you are using tokyonight you can override colors for specific parts of interface. I've personally found success with setting fg_gutter (you can find all variables you can override here).

My after/plugin/theme.lua:

local tokyotheme = require("tokyonight")
tokyotheme.setup({
  on_colors = function (colors)
    colors.fg_gutter = "#b2b8cf"
  end
})

This changes all line numbers color to the one specified in snippet.

Gag answered 17/4, 2023 at 22:10 Comment(0)
C
1
  require("tokyonight").setup {
    on_highlights = function(hl, colors)
      hl.LineNr = {
        fg = "#fffb7b",
      }
      hl.CursorLineNr = {
        fg = colors.orange,
      }
    end,
  }

https://github.com/folke/tokyonight.nvim/issues/100

Coseismal answered 11/8, 2023 at 3:16 Comment(2)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Damien
I couldn't get hl.CursorLineNr to work. Otherwise, I liked the solution and LineNr worked.Fled
T
0

To achieve exactly what OP wanted, this config should work. This changes the color of the line numbering above the cursor to blue and below to red:

config = function()
  require('tokyonight').setup {
    on_highlights = function(hl)
      hl.LineNrAbove = {
        fg = '#6ab8ff',
      }
      hl.LineNrBelow = {
        fg = '#ff6188',
      }
     end,
  }
  vim.cmd [[colorscheme tokyonight]]
end,

Make sure to set the colorscheme with vim.cmd after changing the hex colors.

There are more options/colors available, which can be found here. If you want to change options/colors, which are not a child of the local highlights object, make sure to use on_colors instead of on_highlights.

Teutonic answered 1/6, 2024 at 22:54 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.