my nix dotfiles
at master 85 lines 3.5 kB view raw
1vim.cmd('syntax on') 2 3local function detect_background() 4 vim.system( 5 { 'defaults', 'read', '-g', 'AppleInterfaceStyle' }, 6 { text = true }, 7 function(out) 8 local bg = (out.stdout or ''):match('Dark') and 'dark' or 'light' 9 vim.schedule(function() 10 if bg ~= vim.o.background then vim.o.background = bg end 11 end) 12 end 13 ) 14end 15 16local function apply() 17 vim.cmd('hi clear') 18 19 vim.api.nvim_set_hl(0, 'Normal', { bg = 'NONE', fg = 'NONE' }) 20 vim.api.nvim_set_hl(0, 'NormalNC', { bg = 'NONE', fg = 'NONE' }) 21 22 local gray = vim.o.background == 'dark' and '#767676' or '#8a8a8a' 23 vim.api.nvim_set_hl(0, 'Comment', { fg = gray, italic = true }) 24 vim.api.nvim_set_hl(0, '@comment', { fg = gray, italic = true }) 25 26 local indent_fg = vim.o.background == 'dark' and '#3a3a3a' or '#d8d8d8' 27 vim.api.nvim_set_hl(0, 'Whitespace', { fg = indent_fg }) 28 29 -- clear syntax groups (colors + bold) 30 for _, group in ipairs({ 31 'Statement', 'Keyword', 'Function', 'Type', 'PreProc', 'Special', 32 'Identifier', 'Constant', 'String', 'Number', 'Boolean', 'Operator', 33 'Title', 'Bold', 'Italic', 'Include', 'Define', 'Macro', 'Structure', 34 'StorageClass', 'Typedef', 'Tag', 'Delimiter', 'SpecialComment', 35 }) do 36 vim.api.nvim_set_hl(0, group, {}) 37 end 38 39 -- selection / search: match ghostty theme 40 local sel_bg = vim.o.background == 'dark' and '#509c93' or '#fceccc' 41 local sel_fg = vim.o.background == 'dark' and '#fff6e3' or '#4a443d' 42 vim.api.nvim_set_hl(0, 'Visual', { bg = sel_bg, fg = sel_fg }) 43 vim.api.nvim_set_hl(0, 'Search', { bg = sel_bg, fg = sel_fg }) 44 vim.api.nvim_set_hl(0, 'IncSearch', { bg = sel_bg, fg = sel_fg }) 45 46 -- float (hover/diagnostic popups) 47 vim.api.nvim_set_hl(0, 'NormalFloat', { bg = 'NONE', fg = 'NONE' }) 48 vim.api.nvim_set_hl(0, 'FloatBorder', { fg = gray }) 49 50 -- status bar: no inversion 51 vim.api.nvim_set_hl(0, 'StatusLine', { bg = 'NONE', fg = 'NONE' }) 52 vim.api.nvim_set_hl(0, 'StatusLineNC', { bg = 'NONE', fg = 'NONE' }) 53 54 -- diff (vimdiff mode + diff syntax files) 55 if vim.o.background == 'dark' then 56 vim.api.nvim_set_hl(0, 'DiffAdd', { bg = '#1e3828' }) 57 vim.api.nvim_set_hl(0, 'DiffDelete', { bg = '#3a1e1e' }) 58 vim.api.nvim_set_hl(0, 'DiffChange', { bg = '#1e2c3a' }) 59 vim.api.nvim_set_hl(0, 'DiffText', { bg = '#2e4560' }) 60 vim.api.nvim_set_hl(0, 'diffAdded', { fg = '#7ec899' }) 61 vim.api.nvim_set_hl(0, 'diffRemoved', { fg = '#e07070' }) 62 vim.api.nvim_set_hl(0, 'diffChanged', { fg = '#7ab0d8' }) 63 else 64 vim.api.nvim_set_hl(0, 'DiffAdd', { bg = '#b8f0c8' }) 65 vim.api.nvim_set_hl(0, 'DiffDelete', { bg = '#f0b8b8' }) 66 vim.api.nvim_set_hl(0, 'DiffChange', { bg = '#b8d8f8' }) 67 vim.api.nvim_set_hl(0, 'DiffText', { bg = '#80b8f0' }) 68 vim.api.nvim_set_hl(0, 'diffAdded', { fg = '#2a7a3a' }) 69 vim.api.nvim_set_hl(0, 'diffRemoved', { fg = '#b03030' }) 70 vim.api.nvim_set_hl(0, 'diffChanged', { fg = '#2060a0' }) 71 end 72 73 -- diagnostics: underline only 74 for _, kind in ipairs({ 'Error', 'Warn', 'Info', 'Hint' }) do 75 vim.api.nvim_set_hl(0, 'DiagnosticUnderline' .. kind, { underline = true }) 76 vim.api.nvim_set_hl(0, 'Diagnostic' .. kind, {}) 77 end 78end 79 80detect_background() 81apply() 82 83vim.api.nvim_create_autocmd('OptionSet', { pattern = 'background', callback = apply }) 84vim.api.nvim_create_autocmd('FocusGained', { callback = detect_background }) 85vim.api.nvim_create_autocmd('VimEnter', { once = true, callback = apply })