Search code examples
luaneovim

Why neovim can't render a background color?


I'm trying to change the background of the neovim using lua.

-- init.lua

vim.o.termguicolors = true

vim.api.nvim_set_hl(0, "Normal", { bg="#04110d" })

The expected result should be like this (modified directly via Terminal settings)

enter image description here

But it renders like this

enter image description here

I use the default Ubuntu Terminal with default configuration.

I tried to use a "simplier" color and it works

Instead of this

vim.api.nvim_set_hl(0, "Normal", { bg="#04110d" })

I used this

vim.api.nvim_set_hl(0, "Normal", { bg="#ff0000" })

enter image description here

(sorry for the red image)

Does anyone know the root cause of the problem and how I can fix that?

I'd expect the specified color #04110d to work as expected (displaying the dark green background).

Thanks


Solution

  • I found the root cause of the problem. The issue was with tmux.

    For some reason tmux couldn't properly render some colors. By setting the following command in the tmux config, the #04110d color started to display as expected.

    -- ~/.tmux.conf
    
    set-option -ga terminal-overrides ",xterm-256color:Tc"
    

    Also see - Neovim colorscheme does not look right when using nvim inside tmux