From 50ef2906429250af5e30fd3121742d6e022a7b5c Mon Sep 17 00:00:00 2001 From: mace Date: Fri, 28 Aug 2026 10:02:40 +0200 Subject: [PATCH] fix color transparancy issues --- init.lua | 5 ++++- lua/custom/colortheme.lua | 28 ++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/init.lua b/init.lua index a1dd633..9a945d4 100644 --- a/init.lua +++ b/init.lua @@ -274,9 +274,12 @@ require('custom.colorizer') require('custom.keymaps') require('custom.harpoon') require('custom.mason') -require('custom.bufferline') require('custom.kulala') require('custom.rainbow') require('custom.none-ls') require('custom.gitsigns') require('custom.colortheme') +-- bufferline derives its colors from the Normal highlight group at setup() +-- time, so it must load after the colorscheme is applied above, or it +-- captures the pre-colorscheme (solid) background instead of the final one. +require('custom.bufferline') diff --git a/lua/custom/colortheme.lua b/lua/custom/colortheme.lua index 24641bf..7f1d08e 100644 --- a/lua/custom/colortheme.lua +++ b/lua/custom/colortheme.lua @@ -1,9 +1,3 @@ -vim.api.nvim_create_autocmd("ColorScheme", { - callback = function() - vim.api.nvim_set_hl(0, "NormalFloat", { bg = "NONE", fg = "#cdd6f5" }) - vim.api.nvim_set_hl(0, "FloatBorder", { bg = "NONE", fg = "#3e4452" }) - end -}) -- Detect dark or light theme saved in .colorscheme. defaults to dark local background_mode local f = io.open(os.getenv('HOME') .. '/.colorscheme', 'r') @@ -15,6 +9,26 @@ else background_mode = 'dark' end +-- Applying these via the ColorScheme autocmd (rather than one-off `:highlight` +-- calls after the colorscheme is set) means every plugin that listens for +-- ColorScheme to pick up transparency - not just whatever runs immediately +-- after this file - sees the final, transparent highlights too. +vim.api.nvim_create_autocmd("ColorScheme", { + callback = function() + vim.api.nvim_set_hl(0, "NormalFloat", { bg = "NONE", fg = "#cdd6f5" }) + vim.api.nvim_set_hl(0, "FloatBorder", { bg = "NONE", fg = "#3e4452" }) + if background_mode ~= 'dark' then + vim.api.nvim_set_hl(0, "Normal", { bg = "NONE" }) + vim.api.nvim_set_hl(0, "StatusLine", { bg = "NONE" }) + vim.api.nvim_set_hl(0, "LineNr", { bg = "NONE" }) + vim.api.nvim_set_hl(0, "CursorLineNr", { bg = "NONE" }) + vim.api.nvim_set_hl(0, "TabLine", { bg = "NONE" }) + vim.api.nvim_set_hl(0, "Visual", { bg = "NONE" }) + vim.api.nvim_set_hl(0, "NormalNC", { bg = "NONE" }) + end + end +}) + -- use ayu theme for dark mode, selenized for light mode if background_mode == 'dark' then vim.g.ayucolor = background_mode @@ -23,6 +37,4 @@ if background_mode == 'dark' then else vim.cmd("colorscheme zenbones") vim.cmd("set background=" .. background_mode) - vim.cmd( - 'highlight Normal ctermbg=NONE guibg=NONE | highlight StatusLine ctermbg=NONE guibg=NONE | highlight LineNr ctermbg=NONE guibg=NONE | highlight CursorLineNr ctermbg=NONE guibg=NONE | highlight TabLine ctermbg=NONE guibg=NONE | highlight Visual ctermbg=NONE guibg=NONE | highlight NormalNC ctermbg=NONE guibg=NONE') end