vim.cmd('syntax on') local function detect_background() vim.system( { 'defaults', 'read', '-g', 'AppleInterfaceStyle' }, { text = true }, function(out) local bg = (out.stdout or ''):match('Dark') and 'dark' or 'light' vim.schedule(function() if bg ~= vim.o.background then vim.o.background = bg end end) end ) end local function apply() vim.cmd('hi clear') vim.api.nvim_set_hl(0, 'Normal', { bg = 'NONE', fg = 'NONE' }) vim.api.nvim_set_hl(0, 'NormalNC', { bg = 'NONE', fg = 'NONE' }) local gray = vim.o.background == 'dark' and '#767676' or '#8a8a8a' vim.api.nvim_set_hl(0, 'Comment', { fg = gray, italic = true }) vim.api.nvim_set_hl(0, '@comment', { fg = gray, italic = true }) local indent_fg = vim.o.background == 'dark' and '#3a3a3a' or '#d8d8d8' vim.api.nvim_set_hl(0, 'Whitespace', { fg = indent_fg }) -- clear syntax groups (colors + bold) for _, group in ipairs({ 'Statement', 'Keyword', 'Function', 'Type', 'PreProc', 'Special', 'Identifier', 'Constant', 'String', 'Number', 'Boolean', 'Operator', 'Title', 'Bold', 'Italic', 'Include', 'Define', 'Macro', 'Structure', 'StorageClass', 'Typedef', 'Tag', 'Delimiter', 'SpecialComment', }) do vim.api.nvim_set_hl(0, group, {}) end -- selection / search: match ghostty theme local sel_bg = vim.o.background == 'dark' and '#509c93' or '#fceccc' local sel_fg = vim.o.background == 'dark' and '#fff6e3' or '#4a443d' vim.api.nvim_set_hl(0, 'Visual', { bg = sel_bg, fg = sel_fg }) vim.api.nvim_set_hl(0, 'Search', { bg = sel_bg, fg = sel_fg }) vim.api.nvim_set_hl(0, 'IncSearch', { bg = sel_bg, fg = sel_fg }) -- float (hover/diagnostic popups) vim.api.nvim_set_hl(0, 'NormalFloat', { bg = 'NONE', fg = 'NONE' }) vim.api.nvim_set_hl(0, 'FloatBorder', { fg = gray }) -- status bar: no inversion vim.api.nvim_set_hl(0, 'StatusLine', { bg = 'NONE', fg = 'NONE' }) vim.api.nvim_set_hl(0, 'StatusLineNC', { bg = 'NONE', fg = 'NONE' }) -- diff (vimdiff mode + diff syntax files) if vim.o.background == 'dark' then vim.api.nvim_set_hl(0, 'DiffAdd', { bg = '#1e3828' }) vim.api.nvim_set_hl(0, 'DiffDelete', { bg = '#3a1e1e' }) vim.api.nvim_set_hl(0, 'DiffChange', { bg = '#1e2c3a' }) vim.api.nvim_set_hl(0, 'DiffText', { bg = '#2e4560' }) vim.api.nvim_set_hl(0, 'diffAdded', { fg = '#7ec899' }) vim.api.nvim_set_hl(0, 'diffRemoved', { fg = '#e07070' }) vim.api.nvim_set_hl(0, 'diffChanged', { fg = '#7ab0d8' }) else vim.api.nvim_set_hl(0, 'DiffAdd', { bg = '#b8f0c8' }) vim.api.nvim_set_hl(0, 'DiffDelete', { bg = '#f0b8b8' }) vim.api.nvim_set_hl(0, 'DiffChange', { bg = '#b8d8f8' }) vim.api.nvim_set_hl(0, 'DiffText', { bg = '#80b8f0' }) vim.api.nvim_set_hl(0, 'diffAdded', { fg = '#2a7a3a' }) vim.api.nvim_set_hl(0, 'diffRemoved', { fg = '#b03030' }) vim.api.nvim_set_hl(0, 'diffChanged', { fg = '#2060a0' }) end -- diagnostics: underline only for _, kind in ipairs({ 'Error', 'Warn', 'Info', 'Hint' }) do vim.api.nvim_set_hl(0, 'DiagnosticUnderline' .. kind, { underline = true }) vim.api.nvim_set_hl(0, 'Diagnostic' .. kind, {}) end end detect_background() apply() vim.api.nvim_create_autocmd('OptionSet', { pattern = 'background', callback = apply }) vim.api.nvim_create_autocmd('FocusGained', { callback = detect_background }) vim.api.nvim_create_autocmd('VimEnter', { once = true, callback = apply })