-- Git enhancement plugins -- -- Change markers and blame both come from gitsigns.nvim (LazyVim's default; the -- editor.mini-diff extra is off in lazyvim.json because it disables gitsigns). local MIN_BLAME_ROOM = 12 -- columns needed before the summary is worth showing local blame_hl = "GitSignsCurrentLineBlame" -- Current-line blame that fits the window: "author, 3 days ago · summary". The -- summary is cut to the room left after the line's text, and dropped when the -- line nearly fills the window, so the annotation never runs off screen. local function blame_formatter(_, info) if info.author == "Not Committed Yet" then return { { " ● Uncommitted change", "GitSignsChange" } } end local util = require("gitsigns.util") local head = (" %s, %s"):format(info.author, util.get_relative_time(tonumber(info.author_time))) local win = vim.api.nvim_get_current_win() local textoff = vim.fn.getwininfo(win)[1].textoff local room = vim.api.nvim_win_get_width(win) - textoff - vim.api.nvim_strwidth(vim.api.nvim_get_current_line()) - vim.api.nvim_strwidth(head) - 4 if room < MIN_BLAME_ROOM then return { { head, blame_hl } } end local summary = info.summary or "" if vim.api.nvim_strwidth(summary) > room then summary = vim.fn.strcharpart(summary, 0, room - 1) .. "…" end return { { head, blame_hl }, { " · " .. summary, blame_hl } } end return { { "lewis6991/gitsigns.nvim", opts = { -- Heavy bars in the sign column, VS Code style. Unstaged changes use -- GitSignsAdd/Change/Delete; staged ones get gitsigns' dimmer variants. signs = { add = { text = "┃" }, change = { text = "┃" }, delete = { text = "▁" }, topdelete = { text = "▔" }, changedelete = { text = "┃" }, untracked = { text = "┆" }, }, signs_staged = { add = { text = "┃" }, change = { text = "┃" }, delete = { text = "▁" }, topdelete = { text = "▔" }, changedelete = { text = "┃" }, }, numhl = true, -- also color the line number of every changed line attach_to_untracked = true, current_line_blame = true, current_line_blame_opts = { virt_text_pos = "eol", delay = 300, ignore_whitespace = true }, current_line_blame_formatter = blame_formatter, current_line_blame_formatter_nc = blame_formatter, }, keys = { { "gb", "Gitsigns blame", desc = "Blame panel (every line)" }, { "gL", function() require("gitsigns").blame_line({ full = true }) end, desc = "Blame line (full commit)" }, { "uB", "Gitsigns toggle_current_line_blame", desc = "Toggle inline blame" }, { "uN", "Gitsigns toggle_numhl", desc = "Toggle git line-number colors" }, }, }, -- Advanced git diff viewer -- Better git diff interface with file history -- Open with :DiffviewOpen, :DiffviewFileHistory { "sindrets/diffview.nvim", cmd = { "DiffviewOpen", "DiffviewClose", "DiffviewToggleFiles", "DiffviewFocusFiles", "DiffviewFileHistory" }, opts = { enhanced_diff_hl = true, view = { default = { layout = "diff2_horizontal" }, file_history = { layout = "diff2_horizontal" }, }, }, keys = { { "gd", "DiffviewOpen", desc = "Open Diffview" }, { "gh", "DiffviewFileHistory %", desc = "File History" }, { "gH", "DiffviewFileHistory", desc = "Repo History" }, }, }, }