From 62fb1f2f6e6092ea653d9ce7c0dfd99fc45c9900 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Thu, 19 Dec 2024 13:58:57 +0100 Subject: nvim: use gitsigns --- nvim/nvim/init.lua | 2 ++ nvim/nvim/lua/git.lua | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 nvim/nvim/lua/git.lua diff --git a/nvim/nvim/init.lua b/nvim/nvim/init.lua index 9428c32..672ea11 100644 --- a/nvim/nvim/init.lua +++ b/nvim/nvim/init.lua @@ -7,6 +7,7 @@ vim.fn["plug#begin"]() Plug("nvim-treesitter/nvim-treesitter") Plug("julienvincent/nvim-paredit") -- Some paredit commands Plug("windwp/nvim-autopairs") -- Autobalance parens + Plug("lewis6991/gitsigns.nvim") Plug('luizribeiro/vim-cooklang') Plug('Mofiqul/dracula.nvim') Plug("othree/html5.vim") @@ -157,3 +158,4 @@ require 'mappings' require 'highlight' require 'colors' require 'parens' +require 'git' diff --git a/nvim/nvim/lua/git.lua b/nvim/nvim/lua/git.lua new file mode 100644 index 0000000..95d4931 --- /dev/null +++ b/nvim/nvim/lua/git.lua @@ -0,0 +1,45 @@ +local gitsigns = require 'gitsigns' +gitsigns.setup({ + on_attach = function(bufnr) + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end + + -- Navigation + map('n', ']c', function() + if vim.wo.diff then + vim.cmd.normal({']c', bang = true}) + else + gitsigns.nav_hunk('next') + end + end) + + map('n', '[c', function() + if vim.wo.diff then + vim.cmd.normal({'[c', bang = true}) + else + gitsigns.nav_hunk('prev') + end + end) + + -- Actions + map('n', 'hs', gitsigns.stage_hunk) + map('n', 'hr', gitsigns.reset_hunk) + map('v', 'hs', function() gitsigns.stage_hunk {vim.fn.line('.'), vim.fn.line('v')} end) + map('v', 'hr', function() gitsigns.reset_hunk {vim.fn.line('.'), vim.fn.line('v')} end) + -- 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', function() gitsigns.blame_line{full=true} end) + map('n', 'tb', gitsigns.toggle_current_line_blame) + map('n', 'hd', gitsigns.diffthis) + map('n', 'hD', function() gitsigns.diffthis('~') end) + map('n', 'td', gitsigns.toggle_deleted) + + -- Text object + map({'o', 'x'}, 'ih', ':Gitsigns select_hunk') + end +}) -- cgit v1.2.3