How to convert this(color theme related) vimscript to lua?

I have these 2 lines in my init.vim to set the background color to transparent:

hi Normal guibg=NONE ctermbg=NONE
hi LineNr guibg=NONE ctermbg=NONE

How to convert these lines to Lua?

I tried vim.api.nvim_eval('...') , vim.api.nvim_command('...') and vim.api.nvim_exec('...') but none of these seem to work.

vim.cmd [[hi Normal guibg=NONE ctermbg=NONE]]
1 Like

Thanks for the answer. It worked.

Unfortunately setting only above 2 lines is not enough to make the whole thing transparent. I’m also using some other plugins, like lualine that I was not using earlier. I’m actually using LunarVim config. And I wonder how can I find out, what are all the things for which I need to set the background to NONE. Just in case anybody could help.

You want to wrap them in an augroup for it to work when the ColorScheme event happens:

vim.cmd([[
  augroup transparent_hl
    au!
    au ColorScheme * hi Normal guibg=NONE ctermbg=NONE
    au ColorScheme * hi LineNr guibg=NONE ctermbg=NONE
  augroup END
]])
1 Like