From 8d0780f666fe7716397e9824624e0aced85670e5 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar Date: Sat, 12 Sep 2026 05:57:11 +0530 Subject: feat(development/nixvim): gitsigns configurations Finally made a fully featured gitsigns config integrating all its features. --- modules/development/nixvim/plugins/gitsigns.nix | 102 ++++++++++++++++++++++- modules/development/nixvim/plugins/telescope.nix | 10 --- 2 files changed, 99 insertions(+), 13 deletions(-) (limited to 'modules/development/nixvim/plugins') diff --git a/modules/development/nixvim/plugins/gitsigns.nix b/modules/development/nixvim/plugins/gitsigns.nix index 38ad85f..ccfb2c9 100644 --- a/modules/development/nixvim/plugins/gitsigns.nix +++ b/modules/development/nixvim/plugins/gitsigns.nix @@ -1,7 +1,103 @@ -# Git status in the sign column +# Git integration: signs, blame, diffs and hunk operations { config, lib, ... }: { - config.programs.nixvim.plugins.gitsigns = lib.mkIf config.development.nixvim.enable { - enable = true; + config.programs.nixvim = lib.mkIf config.development.nixvim.enable { + plugins.gitsigns = { + enable = true; + + settings = { + signs = { + add.text = "┃"; + change.text = "┃"; + delete.text = "▁"; + topdelete.text = "▔"; + changedelete.text = "~"; + untracked.text = "┆"; + }; + + numhl = true; + current_line_blame = false; + current_line_blame_formatter = ", - "; + + on_attach = '' + function(bufnr) + local gitsigns = require('gitsigns') + local function map(mode, lhs, rhs, desc) + vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, silent = true, desc = desc }) + end + + -- Navigation + map('n', ']c', function() gitsigns.nav_hunk('next') end, 'Next hunk') + map('n', '[c', function() gitsigns.nav_hunk('prev') end, 'Previous hunk') + map('n', ']C', function() gitsigns.nav_hunk('last') end, 'Last hunk') + map('n', '[C', function() gitsigns.nav_hunk('first') end, 'First hunk') + + -- Hunk actions + map('n', 'gs', gitsigns.stage_hunk, 'Stage hunk') + map('v', 'gs', function() + gitsigns.stage_hunk({ vim.fn.line('.'), vim.fn.line('v') }) + end, 'Stage visual range hunk') + map('n', 'gr', gitsigns.reset_hunk, 'Reset hunk') + map('v', 'gr', function() + gitsigns.reset_hunk({ vim.fn.line('.'), vim.fn.line('v') }) + end, 'Reset visual range hunk') + map('n', 'gS', gitsigns.stage_buffer, 'Stage buffer') + map('n', 'gR', gitsigns.reset_buffer, 'Reset buffer') + map('n', 'gi', gitsigns.reset_buffer_index, 'Unstage buffer (reset index)') + map('n', 'gu', gitsigns.undo_stage_hunk, 'Undo stage hunk') + + -- Preview + map('n', 'gp', gitsigns.preview_hunk, 'Preview hunk') + map('n', 'gP', gitsigns.preview_hunk_inline, 'Preview hunk inline') + + -- Blame + map('n', 'gb', gitsigns.blame_line, 'Blame line') + map('n', 'gB', function() + gitsigns.blame_line({ full = true }) + end, 'Blame line (full)') + + -- Diffs / base + map('n', 'gd', gitsigns.diffthis, 'Diff this (index)') + map('n', 'gD', function() + gitsigns.diffthis('~') + end, 'Diff this (HEAD)') + map('n', 'gc', function() + gitsigns.change_base(nil, true) + end, 'Change diff base') + + -- Quickfix / location list + map('n', 'gq', gitsigns.setqflist, 'Hunks to quickfix') + map('n', 'gQ', function() + gitsigns.setqflist('all') + end, 'Repo hunks to quickfix') + map('n', 'gl', gitsigns.setloclist, 'Hunks to location list') + + -- Toggles + map('n', 'gts', gitsigns.toggle_signs, 'Toggle signs') + map('n', 'gtl', gitsigns.toggle_linehl, 'Toggle line highlight') + map('n', 'gtn', gitsigns.toggle_numhl, 'Toggle number highlight') + map('n', 'gtw', gitsigns.toggle_word_diff, 'Toggle word diff') + map('n', 'gtb', gitsigns.toggle_current_line_blame, 'Toggle current line blame') + map('n', 'gtd', gitsigns.toggle_deleted, 'Toggle deleted lines') + + -- Misc + map('n', 'gF', gitsigns.refresh, 'Refresh gitsigns') + + -- Text object + map({ 'o', 'x' }, 'ih', gitsigns.select_hunk, 'Select hunk text object') + end + ''; + }; + }; + + highlight = with config.scheme.withHashtag; { + GitSignsAdd.fg = base0B; + GitSignsChange.fg = base0A; + GitSignsDelete.fg = base08; + GitSignsTopdelete.fg = base08; + GitSignsChangedelete.fg = base0A; + GitSignsUntracked.fg = base0C; + GitSignsCurrentLineBlame.fg = base04; + }; }; } diff --git a/modules/development/nixvim/plugins/telescope.nix b/modules/development/nixvim/plugins/telescope.nix index 8f06ec9..505a3eb 100644 --- a/modules/development/nixvim/plugins/telescope.nix +++ b/modules/development/nixvim/plugins/telescope.nix @@ -56,16 +56,6 @@ options.desc = "Document symbols"; }; - # Git - "gc" = { - action = "git_commits"; - options.desc = "Git commits"; - }; - "gb" = { - action = "git_branches"; - options.desc = "Git branches"; - }; - # Misc "fh" = { action = "help_tags"; -- cgit v1.2.3