From 765c538d9a44a8dc5e0a4626841a19dda8fedd9e Mon Sep 17 00:00:00 2001 From: Felix Tenley Date: Wed, 30 Mar 2022 01:37:02 +0200 Subject: [PATCH] feat(neovim): extend gitsigns config --- home/editors/neovim/gitsigns.lua | 35 +++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/home/editors/neovim/gitsigns.lua b/home/editors/neovim/gitsigns.lua index 91fa65b..2b9ad65 100644 --- a/home/editors/neovim/gitsigns.lua +++ b/home/editors/neovim/gitsigns.lua @@ -1 +1,34 @@ -require('gitsigns').setup() +-- TODO vim.keymap.set not yet supported on stable neovim +-- see gitsigns repo for sample when migrating to vim.keymap.set + +require("gitsigns").setup { + on_attach = function(bufnr) + local function map(mode, lhs, rhs, opts) + opts = vim.tbl_extend('force', {noremap = true, silent = true}, opts or {}) + vim.api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, opts) + end + + -- Navigation + map("n", "]c", "&diff ? ']c' : 'Gitsigns next_hunk'", { expr = true }) + map("n", "[c", "&diff ? '[c' : 'Gitsigns prev_hunk'", { expr = true }) + + -- Actions + map("n", "hs", ":Gitsigns stage_hunk") + map("v", "hs", ":Gitsigns stage_hunk") + map("n", "hr", ":Gitsigns reset_hunk") + map("v", "hr", ":Gitsigns reset_hunk") + map("n", "hS", "Gitsigns stage_buffer") + map("n", "hu", "Gitsigns undo_stage_hunk") + map("n", "hR", "Gitsigns reset_buffer") + map("n", "hp", "Gitsigns preview_hunk") + map("n", "hb", "lua require'gitsigns'.blame_line{full=true}") + map("n", "tb", "Gitsigns toggle_current_line_blame") + map("n", "hd", "Gitsigns diffthis") + map("n", "hD", "lua require'gitsigns'.diffthis('~')") + map("n", "td", "Gitsigns toggle_deleted") + + -- Text object + map("o", "ih", ":Gitsigns select_hunk") + map("x", "ih", ":Gitsigns select_hunk") + end +}