require('gitsigns').setup{ current_line_blame_opts = { virt_text = true, virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align' delay = 200, ignore_whitespace = false, virt_text_priority = 100, }, 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) map('n', '[c', function() if vim.wo.diff then vim.cmd.normal({'[c', bang = true}) else gitsigns.nav_hunk('prev') end end) -- Actions map('n', 'hs', gitsigns.stage_hunk, { desc = 'stage hunk' }) map('n', 'hr', gitsigns.reset_hunk, { desc = 'reset hunk' }) map('n', 'hS', gitsigns.stage_buffer, { desc = 'stage buffer' }) map('n', 'hu', gitsigns.undo_stage_hunk, { desc = 'undo stage hunk' }) map('n', 'hR', gitsigns.reset_buffer, { desc = 'reset buffer' }) map('n', 'hp', gitsigns.preview_hunk, { desc = 'preview hunk' }) map('n', 'hb', function() gitsigns.blame_line{full=true} end, { desc = 'hunk blame' }) map('n', 'tb', gitsigns.toggle_current_line_blame, { desc = 'toggle single line blame' }) map('n', 'hd', gitsigns.diffthis, { desc = 'hunk diff' }) map('n', 'hD', function() gitsigns.diffthis('~') end, { desc = 'diff deleted' }) map('n', 'td', gitsigns.toggle_deleted, { desc = 'toggle deleted' }) end }