From b8c25c7bc17d1c982a719670d125bd81b7a0359a Mon Sep 17 00:00:00 2001 From: cole-maxwell1 Date: Wed, 22 Apr 2026 09:26:02 -0500 Subject: [PATCH] Add: diff colors and dynamic diff window width sizing --- .config/nvim/lua/cole/set.lua | 67 +++++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 6 deletions(-) diff --git a/.config/nvim/lua/cole/set.lua b/.config/nvim/lua/cole/set.lua index bd5af80..4d82f35 100644 --- a/.config/nvim/lua/cole/set.lua +++ b/.config/nvim/lua/cole/set.lua @@ -1,21 +1,76 @@ ---Line numbers +-- Line numbers vim.opt.nu = true vim.opt.relativenumber = true ---Formatting +-- Formatting vim.opt.tabstop = 4 vim.opt.shiftwidth = 4 vim.opt.expandtab = true vim.opt.smartindent = true ---Search +-- Search vim.opt.hlsearch = false vim.opt.incsearch = true ---Scroll settings -vim.opt.scrolloff = 8 --Always 8 lines above +-- Scroll settings +vim.opt.scrolloff = 8 -- Always 8 lines above ---Color scheme +-- Color scheme vim.cmd.colorscheme("habamax") +-- Diff: Muted Red on Crimson +vim.api.nvim_set_hl(0, "DiffAdd", { + bg = "#1e3a1e", + fg = "NONE" +}) -- added lines: muted green +vim.api.nvim_set_hl(0, "DiffDelete", { + bg = "#3d1a1a", + fg = "#6b3a3a" +}) -- deleted lines: muted red +vim.api.nvim_set_hl(0, "DiffChange", { + bg = "#3a1c1c", + fg = "NONE" +}) -- changed lines: light red wash +vim.api.nvim_set_hl(0, "DiffText", { + bg = "#8b2035", + fg = "NONE", + bold = true +}) -- char diff: saturated red (crimson) + +-- Dynamic diff window width sizing +vim.api.nvim_create_autocmd("VimEnter", { + callback = function() + if not vim.wo.diff then + return + end + + -- Calculate the longest display-width line in the left (current) buffer. + local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) + local max_len = 0 + for _, line in ipairs(lines) do + local len = vim.fn.strdisplaywidth(line) + if len > max_len then + max_len = len + end + end + + -- Account for gutter columns (line numbers, sign column, fold column). + local gutter = 0 + if vim.wo.number or vim.wo.relativenumber then + gutter = gutter + vim.wo.numberwidth + end + if vim.wo.signcolumn ~= "no" then + gutter = gutter + 2 + end + gutter = gutter + vim.wo.foldcolumn + + local desired = max_len + gutter + 1 -- +1 for the right edge padding + + -- Cap at exactly half the terminal width. + local half = math.floor(vim.o.columns / 2) + local width = math.min(desired, half) + + vim.api.nvim_win_set_width(0, width) + end +})