-- Git Configuration local M = {} function M.setup_gitsigns() require('gitsigns').setup({ signs = { add = { text = '+' }, change = { text = '~' }, delete = { text = '_' }, topdelete = { text = '‾' }, changedelete = { text = '~' }, }, on_attach = function(bufnr) local gitsigns = require('gitsigns') local function map(mode, l, r, opts) opts = opts or {} opts.buffer = bufnr vim.keymap.set(mode, l, r, opts) end -- Navigation map('n', ']c', function() if vim.wo.diff then vim.cmd.normal({']c', bang = true}) else gitsigns.nav_hunk('next') end end, { desc = 'Jump to next git [c]hange' }) map('n', '[c', function() if vim.wo.diff then vim.cmd.normal({'[c', bang = true}) else gitsigns.nav_hunk('prev') end end, { desc = 'Jump to previous git [c]hange' }) -- Actions map('n', 'hs', gitsigns.stage_hunk, { desc = 'Git [s]tage hunk' }) map('n', 'hr', gitsigns.reset_hunk, { desc = 'Git [r]eset hunk' }) map('v', 'hs', function() gitsigns.stage_hunk({vim.fn.line('.'), vim.fn.line('v')}) end, { desc = 'Git [s]tage hunk' }) map('v', 'hr', function() gitsigns.reset_hunk({vim.fn.line('.'), vim.fn.line('v')}) end, { desc = 'Git [r]eset hunk' }) map('n', 'hS', gitsigns.stage_buffer, { desc = 'Git [S]tage buffer' }) map('n', 'hu', gitsigns.undo_stage_hunk, { desc = 'Git [u]ndo stage hunk' }) map('n', 'hR', gitsigns.reset_buffer, { desc = 'Git [R]eset buffer' }) map('n', 'hp', gitsigns.preview_hunk, { desc = 'Git [p]review hunk' }) map('n', 'hb', gitsigns.blame_line, { desc = 'Git [b]lame line' }) map('n', 'hd', gitsigns.diffthis, { desc = 'Git [d]iff against index' }) map('n', 'hD', function() gitsigns.diffthis('@') end, { desc = 'Git [D]iff against last commit' }) -- Toggles map('n', 'tb', gitsigns.toggle_current_line_blame, { desc = '[T]oggle git show [b]lame line' }) map('n', 'tD', gitsigns.toggle_deleted, { desc = '[T]oggle git show [D]eleted' }) -- Text object map({'o', 'x'}, 'ih', ':Gitsigns select_hunk', { desc = 'Select git hunk' }) end, }) end return M