Skip to content

Commit

Permalink
refactor(gitsigns): mappings (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephane Pluchart committed Jun 14, 2024
1 parent 00c0c01 commit 9b6f775
Showing 1 changed file with 111 additions and 56 deletions.
167 changes: 111 additions & 56 deletions lua/plugins/gitsigns.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,116 @@
return {
'lewis6991/gitsigns.nvim',
-- event = 'BufReadPre',
event = 'BufReadPre',
cmd = 'Gitsigns',
keys = {
{
'<leader>hn',
function()
if vim.wo.diff then
vim.cmd.normal({ ']c', bang = true })
else
require('gitsigns').nav_hunk('next', { preview = true, navigation_message = 'f' })
end
return 'Ignore'
end,
},
{
'<leader>hN',
function()
if vim.wo.diff then
vim.cmd.normal({ '[c', bang = true })
else
require('gitsigns').nav_hunk('prev', { preview = true, navigation_message = 'f' })
end
return 'Ignore'
end,
},
{
'<leader>hs',
function()
require('gitsigns').stage_hunk()
end,
},
{
'<leader>hs',
{
function()
require('gitsigns').stage_hunk({ vim.fn.line('.'), vim.fn.line('v') })
end,
mode = 'v',
},
},
{
'<leader>hr',
{
function()
require('gitsigns').reset_hunk({ vim.fn.line('.'), vim.fn.line('v') })
end,
mode = 'v',
},
},
{
'<leader>hS',
function()
require('gitsigns').stage_buffer()
end,
},
{
'<leader>hu',
function()
require('gitsigns').undo_stage_hunk()
end,
},
{
'<leader>hR',
function()
require('gitsigns').reset_buffer()
end,
},
{
'<leader>hp',
function()
require('gitsigns').preview_hunk()
end,
},
{
'<leader>hb',
function()
require('gitsigns').blame_line({ full = true })
end,
},
{
'<leader>tb',
function()
require('gitsigns').toggle_current_line_blame()
end,
},
{
'<leader>hd',
function()
require('gitsigns').diffthis()
end,
},
{
'<leader>hD',
function()
require('gitsigns').diffthis('~')
end,
},
{
'<leader>td',
function()
require('gitsigns').toggle_deleted()
end,
},
{
'ih',
{
':<C-U>Gitsigns select_hunk<CR>',
mode = { 'o', 'x' },
},
},
},
config = function()
require('gitsigns').setup({
signs = {
Expand Down Expand Up @@ -30,61 +140,6 @@ return {
ignore_whitespace = false,
virt_text_priority = 99,
},
on_attach = function(bufnr)
local gitsigns = require('gitsigns')
local jump_hunk_opts = { preview = true, navigation_message = 'f' }

local function map(mode, l, r, opts)
opts = opts or {}
opts.buffer = bufnr
vim.keymap.set(mode, l, r, opts)
end

-- Navigation
map('n', '<leader>hn', function()
if vim.wo.diff then
vim.cmd.normal({ ']c', bang = true })
else
gitsigns.nav_hunk('next', jump_hunk_opts)
end
return 'Ignore'
end)

map('n', '<leader>hN', function()
if vim.wo.diff then
vim.cmd.normal({ '[c', bang = true })
else
gitsigns.nav_hunk('prev', jump_hunk_opts)
end
return 'Ignore'
end)

-- Actions
map('n', '<leader>hs', gitsigns.stage_hunk)
map('v', '<leader>hs', function()
gitsigns.stage_hunk({ vim.fn.line('.'), vim.fn.line('v') })
end)
map('v', '<leader>hr', function()
gitsigns.reset_hunk({ vim.fn.line('.'), vim.fn.line('v') })
end)
map('n', '<leader>hS', gitsigns.stage_buffer)
map('n', '<leader>hu', gitsigns.undo_stage_hunk)
map('n', '<leader>hR', gitsigns.reset_buffer)
map('n', '<leader>hr', gitsigns.reset_hunk)
map('n', '<leader>hp', gitsigns.preview_hunk)
map('n', '<leader>hb', function()
gitsigns.blame_line({ full = true })
end)
map('n', '<leader>tb', gitsigns.toggle_current_line_blame)
map('n', '<leader>hd', gitsigns.diffthis)
map('n', '<leader>hD', function()
gitsigns.diffthis('~')
end)
map('n', '<leader>td', gitsigns.toggle_deleted)

-- Text object
map({ 'o', 'x' }, 'ih', ':<C-U>Gitsigns select_hunk<CR>')
end,
})
end,
}

0 comments on commit 9b6f775

Please sign in to comment.