diff --git a/config/neovim/after/plugin/gitsigns.lua b/config/neovim/after/plugin/gitsigns.lua index 14dfb74..cf8f92c 100644 --- a/config/neovim/after/plugin/gitsigns.lua +++ b/config/neovim/after/plugin/gitsigns.lua @@ -8,9 +8,23 @@ gitsigns.setup { numhl = true, } -vim.keymap.set('n', '[h', "Gitsigns prev_hunk"); -vim.keymap.set('n', ']h', "Gitsigns next_hunk"); -vim.keymap.set('n', 'gS', "Gitsigns undo_stage_hunk"); -vim.keymap.set('n', 'gb', "Gitsigns blame_line"); -vim.keymap.set('n', 'gp', "Gitsigns preview_hunk"); -vim.keymap.set('n', 'gs', "Gitsigns stage_hunk"); +local bufnr = vim.api.nvim_get_current_buf() + +local map = require "opdavies.keymap".map +local nmap = require "opdavies.keymap".nmap +local vmap = require "opdavies.keymap".vmap + +nmap { '[h', "&diff ? '[c' : 'Gitsigns prev_hunk'", { expr = true, buffer = bufnr }} +nmap { ']h', "&diff ? ']c' : 'Gitsigns next_hunk'", { expr = true, buffer = bufnr }} + +nmap { 'hR', gitsigns.reset_buffer } +nmap { 'hS', gitsigns.stage_buffer } +nmap { 'hp', gitsigns.preview_hunk } +nmap { 'hr', gitsigns.reset_hunk } +nmap { 'hs', gitsigns.stage_hunk } +nmap { 'hu', gitsigns.undo_stage_hunk } +vmap { 'hr', function() gitsigns.reset_hunk { vim.fn.line('.'), vim.fn.line('v') } end } +vmap { 'hs', function() gitsigns.stage_hunk { vim.fn.line('.'), vim.fn.line('v')} end } + +-- Text object. +map{ {'o', 'x'}, 'ih', ':Gitsigns select_hunk' }