3

I am slowly switching my neovim configurations to Lua. I am currently using the colour scheme https://github.com/nightsense/snow. It sets the background colour to a light-grey, while I want it to be a darker tone of grey. Previously, when using vimL, I used to use the following snippet to change the background colour (to match my terminal colour).

set termguicolors
try
    colorscheme snow
    set background=dark
    hi Normal ctermbg=232 guibg=#0a0a0a
catch /^Vim\%((\a\+)\)\=:E185/
    colorscheme default
endtry

I am trying to achieve the same in my Neovim Lua based configuration. I tried the following piece of code to do so.

vim.cmd('set background=dark')
vim.cmd('colorscheme snow')
vim.cmd('hi Normal guibg=#0a0a0a')

Unfortunately, this does not seem to work. What am I doing wrong here?

1

2 Answers 2

2

This was how I sorted out my problem in the end

vim.api.nvim_command([[
    augroup ChangeBackgroudColour
        autocmd colorscheme * :hi normal guibg=#0a0a0a
    augroup END
]])
vim.o.termguicolors = true
vim.cmd [[silent! colorscheme snow]]
1

I see no particular problem about Lua syntax. Perhaps, you simply forgot to set termguicolors or your console does not support 24-bit color at all. Anyway, the following seems to work just fine:

    vim.o.termguicolors = true
    vim.o.background = "dark"
    vim.cmd [[
        silent! colorscheme snow
        hi Normal guibg=#0a0a0a
    ]]

But note that you have to "patch" background after any colorscheme change, so usually one does make use of an auto-command.

1
  • The above code did not work for me. However, your comment about autocommand gave me a hint to find a solution. I have written down the way I solved this issue as a separate answer.
    – vixiv
    Mar 8, 2021 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.