mirror of
https://github.com/cole-maxwell1/dotfiles.git
synced 2026-06-03 11:10:20 -04:00
Add: diff colors and dynamic diff window width sizing
This commit is contained in:
@@ -19,3 +19,58 @@ vim.opt.scrolloff = 8 --Always 8 lines above
|
||||
-- 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
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user