2022-11-07 16:41:35 +00:00
|
|
|
require('gitsigns').setup {
|
2022-11-02 13:40:30 +00:00
|
|
|
signcolumn = true,
|
|
|
|
numhl = true,
|
2022-11-09 09:25:23 +00:00
|
|
|
linehl = false,
|
2022-11-02 13:40:30 +00:00
|
|
|
current_line_blame = true,
|
2022-11-09 09:19:12 +00:00
|
|
|
word_diff = false,
|
2022-11-02 13:40:30 +00:00
|
|
|
on_attach = function(bufnr)
|
2023-01-25 18:36:39 +00:00
|
|
|
local gs = package.loaded.gitsigns
|
|
|
|
|
|
|
|
local function map(mode, l, r, opts)
|
2023-01-26 11:34:33 +00:00
|
|
|
opts = opts or {}
|
|
|
|
opts.buffer = bufnr
|
|
|
|
vim.keymap.set(mode, l, r, opts)
|
2023-01-25 18:36:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Navigation
|
|
|
|
map('n', ']c', function()
|
2023-01-26 11:34:33 +00:00
|
|
|
if vim.wo.diff then return ']c' end
|
|
|
|
vim.schedule(function() gs.next_hunk() end)
|
|
|
|
return '<Ignore>'
|
|
|
|
end, { expr = true })
|
2023-01-25 18:36:39 +00:00
|
|
|
|
|
|
|
map('n', '[c', function()
|
2023-01-26 11:34:33 +00:00
|
|
|
if vim.wo.diff then return '[c' end
|
|
|
|
vim.schedule(function() gs.prev_hunk() end)
|
|
|
|
return '<Ignore>'
|
|
|
|
end, { expr = true })
|
2023-01-25 18:36:39 +00:00
|
|
|
|
|
|
|
-- Actions
|
2023-01-26 11:34:33 +00:00
|
|
|
map({ 'n', 'v' }, '<leader>hs', ':Gitsigns stage_hunk<CR>')
|
|
|
|
map({ 'n', 'v' }, '<leader>hr', ':Gitsigns reset_hunk<CR>')
|
2023-01-25 18:36:39 +00:00
|
|
|
map('n', '<leader>hS', gs.stage_buffer)
|
|
|
|
map('n', '<leader>hu', gs.undo_stage_hunk)
|
|
|
|
map('n', '<leader>hR', gs.reset_buffer)
|
|
|
|
map('n', '<leader>hp', gs.preview_hunk)
|
2023-01-26 11:34:33 +00:00
|
|
|
map('n', '<leader>hb', function() gs.blame_line { full = true } end)
|
2023-01-25 18:36:39 +00:00
|
|
|
map('n', '<leader>tb', gs.toggle_current_line_blame)
|
|
|
|
map('n', '<leader>hd', gs.diffthis)
|
|
|
|
map('n', '<leader>hD', function() gs.diffthis('~') end)
|
|
|
|
map('n', '<leader>td', gs.toggle_deleted)
|
|
|
|
|
|
|
|
-- Text object
|
2023-01-26 11:34:33 +00:00
|
|
|
map({ 'o', 'x' }, 'ih', ':<C-U>Gitsigns select_hunk<CR>')
|
2022-11-02 13:40:30 +00:00
|
|
|
end,
|
2022-11-01 14:52:38 +00:00
|
|
|
}
|