nvim: after/plugin/gitsigns: Use on_attach callback to setup mappings
keymaps is deprecated.
This commit is contained in:
parent
d946db650e
commit
ba319f2bde
1 changed files with 30 additions and 20 deletions
|
@ -39,27 +39,37 @@ require('gitsigns').setup {
|
||||||
topdelete = { hl = 'GitSignsDelete', text = '‾', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLn' },
|
topdelete = { hl = 'GitSignsDelete', text = '‾', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLn' },
|
||||||
changedelete = { hl = 'GitSignsChange', text = '~', numhl='GitSignsChangeNr', linehl='GitSignsChangeLn' },
|
changedelete = { hl = 'GitSignsChange', text = '~', numhl='GitSignsChangeNr', linehl='GitSignsChangeLn' },
|
||||||
},
|
},
|
||||||
keymaps = {
|
on_attach = function(bufnr)
|
||||||
noremap = true,
|
local gs = package.loaded.gitsigns
|
||||||
|
|
||||||
['n ]c'] = { expr = true, "&diff ? ']c' : '<cmd>lua require\"gitsigns.actions\".next_hunk()<CR>'" },
|
local function map(mode, l, r, opts)
|
||||||
['n [c'] = { expr = true, "&diff ? '[c' : '<cmd>lua require\"gitsigns.actions\".prev_hunk()<CR>'" },
|
opts = opts or {}
|
||||||
|
opts.buffer = bufnr
|
||||||
|
vim.keymap.set(mode, l, r, opts)
|
||||||
|
end
|
||||||
|
|
||||||
['n <Leader>hl'] = '<cmd>lua require"gitsigns".setloclist()<CR>',
|
map('n', ']c', function()
|
||||||
['n <Leader>hp'] = '<cmd>lua require"gitsigns".preview_hunk()<CR>',
|
if vim.wo.diff then return ']c' end
|
||||||
['n <Leader>hq'] = '<cmd>lua require"gitsigns".setqflist()<CR>',
|
vim.schedule(function() gs.next_hunk() end)
|
||||||
['n <Leader>hQ'] = '<cmd>lua require"gitsigns".setqflist("attached")<CR>',
|
return '<Ignore>'
|
||||||
['n <Leader>hr'] = '<cmd>lua require"gitsigns".reset_hunk()<CR>',
|
end, {expr=true})
|
||||||
['v <Leader>hr'] = '<cmd>lua require"gitsigns".reset_hunk({vim.fn.line("."), vim.fn.line("v")})<CR>',
|
|
||||||
['n <Leader>hR'] = '<cmd>lua require"gitsigns".reset_buffer()<CR>',
|
|
||||||
['n <Leader>hs'] = '<cmd>lua require"gitsigns".stage_hunk()<CR>',
|
|
||||||
['v <Leader>hs'] = '<cmd>lua require"gitsigns".stage_hunk({vim.fn.line("."), vim.fn.line("v")})<CR>',
|
|
||||||
['n <Leader>hS'] = '<cmd>lua require"gitsigns".stage_buffer()<CR>',
|
|
||||||
['n <Leader>ht'] = '<cmd>lua require"gitsigns".toggle_signs()<CR>',
|
|
||||||
['n <Leader>hu'] = '<cmd>lua require"gitsigns".undo_stage_hunk()<CR>',
|
|
||||||
['n <Leader>hU'] = '<cmd>lua require"gitsigns".reset_buffer_index()<CR>',
|
|
||||||
|
|
||||||
['o ih'] = ':<C-U>lua require"gitsigns.actions".select_hunk()<CR>',
|
map('n', '[c', function()
|
||||||
['x ih'] = ':<C-U>lua require"gitsigns.actions".select_hunk()<CR>'
|
if vim.wo.diff then return '[c' end
|
||||||
},
|
vim.schedule(function() gs.prev_hunk() end)
|
||||||
|
return '<Ignore>'
|
||||||
|
end, {expr=true})
|
||||||
|
|
||||||
|
map('n', '<Leader>hp', gs.preview_hunk)
|
||||||
|
map('n', '<Leader>hP', gs.preview_hunk_inline)
|
||||||
|
map('n', '<Leader>hl', gs.setloclist)
|
||||||
|
map('n', '<Leader>hq', gs.setqflist)
|
||||||
|
map('n', '<Leader>hQ', function() gs.setqflist('attached') end)
|
||||||
|
map('n', '<Leader>ht', gs.toggle_signs)
|
||||||
|
map('n', '<Leader>hu', gs.undo_stage_hunk)
|
||||||
|
|
||||||
|
map({'n', 'v'}, '<Leader>hs', ':Gitsigns stage_hunk<CR>')
|
||||||
|
map({'n', 'v'}, '<Leader>hr', ':Gitsigns reset_hunk<CR>')
|
||||||
|
map({'o', 'x'}, 'ih', ':<C-U>Gitsigns select_hunk<CR>')
|
||||||
|
end
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue