summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-06-29 17:45:01 +0200
committerThomas Vanbesien <tvanbesi@proton.me>2026-06-29 17:45:53 +0200
commit0e8b2a4a160d4c72b9de345ec81c5e8d540f39ca (patch)
tree077a13a9f4967afa7ba3f1d302c1db0b0bcb1996
parent6a2a43c97810e2288700d24b2b9cd9e83449b73b (diff)
downloadnvim-config-dev.tar.gz
nvim-config-dev.zip
feat(git): replace vim-gitgutter with gitsigns.nvimdev
Swap the diff-sign plugin for gitsigns. Point lualine's diff component at gitsigns' status dict instead of letting it spawn its own git diff.
-rw-r--r--nvim-pack-lock.json8
-rw-r--r--plugin/00-plugin.lua2
-rw-r--r--plugin/50-color.lua9
-rw-r--r--plugin/50-gitsigns.lua67
4 files changed, 81 insertions, 5 deletions
diff --git a/nvim-pack-lock.json b/nvim-pack-lock.json
index 7d06c4f..a7889d2 100644
--- a/nvim-pack-lock.json
+++ b/nvim-pack-lock.json
@@ -4,6 +4,10 @@
"rev": "3ff77862f6c62f7b850668435ae43aa026de8758",
"src": "https://github.com/ibhagwan/fzf-lua"
},
+ "gitsigns.nvim": {
+ "rev": "2038c666bd9d8a0b7349a0b6ee00dc83104b9ecf",
+ "src": "https://github.com/lewis6991/gitsigns.nvim"
+ },
"link.vim": {
"rev": "53e09621fc0dcee54e3231422029be19dab75018",
"src": "https://github.com/qadzek/link.vim"
@@ -48,10 +52,6 @@
"rev": "3b753cf8c6a4dcde6edee8827d464ba9b8c4a6f0",
"src": "https://github.com/tpope/vim-fugitive"
},
- "vim-gitgutter": {
- "rev": "21c977e8597c468c7dc76001389b0b430d46a4b0",
- "src": "https://github.com/airblade/vim-gitgutter"
- },
"vim-surround": {
"rev": "3d188ed2113431cf8dac77be61b842acb64433d9",
"src": "https://github.com/tpope/vim-surround"
diff --git a/plugin/00-plugin.lua b/plugin/00-plugin.lua
index ac34066..6812ced 100644
--- a/plugin/00-plugin.lua
+++ b/plugin/00-plugin.lua
@@ -5,9 +5,9 @@ require() them.
]]
vim.pack.add({
- "https://github.com/airblade/vim-gitgutter",
"https://github.com/ibhagwan/fzf-lua",
"https://github.com/jbyuki/one-small-step-for-vimkind",
+ "https://github.com/lewis6991/gitsigns.nvim",
"https://github.com/maxmx03/solarized.nvim",
"https://github.com/MeanderingProgrammer/render-markdown.nvim",
"https://github.com/mfussenegger/nvim-dap",
diff --git a/plugin/50-color.lua b/plugin/50-color.lua
index f95711c..4cdbad0 100644
--- a/plugin/50-color.lua
+++ b/plugin/50-color.lua
@@ -100,7 +100,16 @@ local function bold_diff_diag()
end
end
+-- Diff counts for lualine's diff component, sourced from gitsigns' status dict.
+local function gitsigns_diff()
+ local gs = vim.b.gitsigns_status_dict
+ if gs then
+ return { added = gs.added, modified = gs.changed, removed = gs.removed }
+ end
+end
+
local lualine_sections = {
+ lualine_b = { "branch", { "diff", source = gitsigns_diff }, "diagnostics" },
lualine_c = { statuses },
lualine_x = { "encoding", "fileformat", "filetype", "lsp_status" },
}
diff --git a/plugin/50-gitsigns.lua b/plugin/50-gitsigns.lua
new file mode 100644
index 0000000..ae9c07a
--- /dev/null
+++ b/plugin/50-gitsigns.lua
@@ -0,0 +1,67 @@
+--[[ 50-gitsigns.lua — git diff signs plus hunk navigation/staging, via gitsigns.nvim.
+
+Signs render by default in the always-on sign column; changed lines and their line numbers
+are highlighted too (linehl/numhl).
+
+Keymaps are buffer-local (set in on_attach):
+`]c`/`[c` navigate hunks (falling through to Vim's builtin diff-mode nav when 'diff' is set)
+`<Leader>h…` stage/reset/preview/blame, and `ih` is a hunk text object.
+
+lualine reads the diff counts from gitsigns (see 50-color.lua).
+]]
+
+local gitsigns = require("gitsigns")
+
+-- Jump to the next/prev hunk, falling through to builtin ]c/[c when in diff mode.
+local function nav_hunk(direction)
+ if vim.wo.diff then
+ vim.cmd.normal({ direction == "next" and "]c" or "[c", bang = true })
+ else
+ gitsigns.nav_hunk(direction)
+ end
+end
+
+-- Stage/reset the visually-selected range of lines.
+local function stage_selection()
+ gitsigns.stage_hunk({ vim.fn.line("."), vim.fn.line("v") })
+end
+local function reset_selection()
+ gitsigns.reset_hunk({ vim.fn.line("."), vim.fn.line("v") })
+end
+
+local function blame_line()
+ gitsigns.blame_line({ full = true })
+end
+
+-- Buffer-local gitsigns keymaps; passed as `on_attach`.
+local function set_keymaps(bufnr)
+ local function map(mode, lhs, rhs, desc)
+ vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, desc = desc })
+ end
+
+ -- Hunk navigation.
+ map("n", "]c", function()
+ nav_hunk("next")
+ end, "Next git hunk")
+ map("n", "[c", function()
+ nav_hunk("prev")
+ end, "Previous git hunk")
+
+ -- Staging / resetting. `stage_hunk` toggles, so it also unstages a staged hunk.
+ map("n", "<Leader>hs", gitsigns.stage_hunk, "Stage/unstage hunk")
+ map("n", "<Leader>hr", gitsigns.reset_hunk, "Reset hunk")
+ map("x", "<Leader>hs", stage_selection, "Stage selected hunk")
+ map("x", "<Leader>hr", reset_selection, "Reset selected hunk")
+ map("n", "<Leader>hS", gitsigns.stage_buffer, "Stage buffer")
+ map("n", "<Leader>hR", gitsigns.reset_buffer, "Reset buffer")
+
+ -- Inspecting.
+ map("n", "<Leader>hp", gitsigns.preview_hunk, "Preview hunk")
+ map("n", "<Leader>hb", blame_line, "Blame line")
+ map("n", "<Leader>hd", gitsigns.diffthis, "Diff against index")
+
+ -- Hunk text object.
+ map({ "o", "x" }, "ih", gitsigns.select_hunk, "Inner git hunk")
+end
+
+gitsigns.setup({ on_attach = set_keymaps, linehl = true, numhl = true })