From a737d0cbc64e3d01e13a1309f349a5fac9c56c83 Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Fri, 1 Apr 2022 22:20:34 +0300 Subject: [PATCH] fix: update gitsigns config --- lua/config/gitsigns.lua | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lua/config/gitsigns.lua b/lua/config/gitsigns.lua index bc29e70..7c3b280 100644 --- a/lua/config/gitsigns.lua +++ b/lua/config/gitsigns.lua @@ -1,4 +1,33 @@ local gitsigns = require 'gitsigns' -gitsigns.setup{} +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 +}