diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-06-12 16:58:39 +0200 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-06-12 22:57:30 +0200 |
| commit | 2e42bf1ef8c27173ed3a540135eada4c24abbaaf (patch) | |
| tree | a7e04f70f47b82e44a0e4721505a315867aac854 /.config/nvim/plugin/50-highlight.lua | |
| parent | 9236e1f700b028da61302be8371401fe0fd86f0c (diff) | |
| download | dotfiles-2e42bf1ef8c27173ed3a540135eada4c24abbaaf.tar.gz dotfiles-2e42bf1ef8c27173ed3a540135eada4c24abbaaf.zip | |
refactor(nvim): rewrite the highlight and extended marks plugins
Diffstat (limited to '.config/nvim/plugin/50-highlight.lua')
| -rw-r--r-- | .config/nvim/plugin/50-highlight.lua | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/.config/nvim/plugin/50-highlight.lua b/.config/nvim/plugin/50-highlight.lua new file mode 100644 index 0000000..1daba82 --- /dev/null +++ b/.config/nvim/plugin/50-highlight.lua @@ -0,0 +1,70 @@ +-- +-- 50-highlight.lua +-- +-- * Creates a function to adjust highlight groups for the solarized colorscheme. It also sets popup +-- menu width and border style. +-- * Creates an autocommand to trigger this function when the background or color scheme changes. +-- * Sets the default colorscheme (solarized) and background (dark). +-- +-- User commands: +-- `ColorsBgToggle`: toggle light/dark background +-- + +-- Adjust highlights (for the solarized theme) to fit my personal tastes. +local function adjust_solarized_highlights() + local colors = { blue = "#268bd2", yellow = "#b58900" } + -- Window bar style + vim.api.nvim_set_hl(0, "WinBarCwd", { fg = colors.blue, italic = true }) + vim.api.nvim_set_hl(0, "WinBarFilePath", { italic = true }) + -- Matching delimiter + vim.api.nvim_set_hl(0, "MatchParen", { link = "CurSearch" }) + -- Floating windows and popup menu windows follow the editor background, their borders too so + -- that the popup menu border draws a clean separation. + vim.opt.pumborder = "rounded" + vim.opt.pumwidth = 25 -- Minimum popup menu width + vim.api.nvim_set_hl(0, "NormalFloat", { link = "Normal" }) + local normal_bg = vim.api.nvim_get_hl(0, { name = "Normal", link = false }).bg + vim.api.nvim_set_hl(0, "FloatBorder", { bg = normal_bg, update = true }) + vim.api.nvim_set_hl(0, "Pmenu", { bg = normal_bg, update = true }) + vim.api.nvim_set_hl(0, "PmenuSbar", { bg = normal_bg, update = true }) + -- Currently selected tabpage + vim.api.nvim_set_hl(0, "TabLineSel", { fg = colors.yellow, bold = true, update = true }) + -- Todo hl group + vim.api.nvim_set_hl(0, "Todo", { bg = "Yellow", fg = "Black", bold = true }) +end + +-- Adjust highlights to fit my personal tastes. +local function adjust_highlights() + if vim.g.colors_name == "solarized" then + adjust_solarized_highlights() + end +end + +local function toggle_theme() + vim.opt.background = vim.o.background == "light" and "dark" or "light" + vim.notify("Color theme set to " .. vim.o.background) +end + +---------------------------------------------------------------------------------------------------- + +vim.api.nvim_create_autocmd("ColorScheme", { + desc = "Adjust custom highlights", + group = vim.g.dotfiles.augroup, + callback = adjust_highlights, +}) + +vim.api.nvim_create_autocmd("OptionSet", { + desc = "Adjust custom highlights on theme change", + pattern = "background", + group = vim.g.dotfiles.augroup, + callback = adjust_highlights, +}) + +vim.api.nvim_create_user_command( + "ColorsBgToggle", + toggle_theme, + { desc = "Toggle light/dark theme" } +) + +vim.cmd.colorscheme("solarized") +vim.opt.background = "dark" |
