vimtricks.wiki Concise Vim tricks, one at a time.

How do I make Neovim's background transparent so the terminal background color or wallpaper shows through?

Answer

vim.api.nvim_set_hl(0, 'Normal', {bg='NONE'})

Explanation

By default, Neovim paints a solid background color defined by the active colorscheme. Setting the Normal highlight group's bg to NONE removes the solid fill, making the background transparent and revealing the terminal's own background color or image.

How it works

  • vim.api.nvim_set_hl(0, group, opts) sets a highlight group in namespace 0 (global)
  • Setting bg = 'NONE' clears the background color, making it transparent
  • This must run after the colorscheme is loaded; place it in a ColorScheme autocmd to survive colorscheme changes

Example

In your init.lua:

local function make_transparent()
  local groups = {'Normal', 'NormalNC', 'NormalFloat', 'SignColumn',
                  'StatusLine', 'StatusLineNC', 'EndOfBuffer'}
  for _, group in ipairs(groups) do
    vim.api.nvim_set_hl(0, group, { bg = 'NONE', ctermbg = 'NONE' })
  end
end

make_transparent()
vim.api.nvim_create_autocmd('ColorScheme', {
  callback = make_transparent,
})

Tips

  • Also clear NormalFloat and FloatBorder for transparent floating windows
  • ctermbg = 'NONE' is needed for 256-color terminals
  • This only works in terminal emulators that support background transparency (most modern ones do)
  • For a one-liner: :lua vim.api.nvim_set_hl(0, 'Normal', {bg='NONE', ctermbg='NONE'})

Next

How do I enable matchit so % jumps between if/else/end style pairs?