my_nvim_config/after/plugin/git_stuff.lua

49 lines
1.8 KiB
Lua

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', '<leader>hs', gitsigns.stage_hunk, { desc = 'stage hunk')
map('n', '<leader>hr', gitsigns.reset_hunk, 'reset hunk')
map('n', '<leader>hS', gitsigns.stage_buffer, 'stage buffer')
map('n', '<leader>hu', gitsigns.undo_stage_hunk, 'undo stage hunk')
map('n', '<leader>hR', gitsigns.reset_buffer, 'reset buffer')
map('n', '<leader>hp', gitsigns.preview_hunk, 'preview hunk')
map('n', '<leader>hb', function() gitsigns.blame_line{full=true} end, 'hunk blame')
map('n', '<leader>tb', gitsigns.toggle_current_line_blame, 'toggle single line blame')
map('n', '<leader>hd', gitsigns.diffthis, 'hunk diff')
map('n', '<leader>hD', function() gitsigns.diffthis('~') end, 'diff deleted')
map('n', '<leader>td', gitsigns.toggle_deleted, 'toggle deleted')
end
}