Skip to content

Commit

Permalink
Add gitsigns config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
miltonllera committed Feb 25, 2022
1 parent 63d43b1 commit ddba281
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lua/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ return require('packer').startup(function(use)
use ({
'lewis6991/gitsigns.nvim',
requires = {'nvim-lua/plenary.nvim'},
config = function() require('gitsigns').setup() end
config = function() require('plugins.gitsigns') end
})

-- LSP server
Expand Down
31 changes: 31 additions & 0 deletions lua/plugins/gitsigns.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require('gitsigns').setup{
on_attach = function(bufnr)
local gs = package.loaded.gitsigns

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', "&diff ? ']c' : '<cmd>Gitsigns next_hunk<CR>'", {expr=true})
map('n', '[c', "&diff ? '[c' : '<cmd>Gitsigns prev_hunk<CR>'", {expr=true})

-- Actions
map({'n', 'v'}, '<leader>hs', ':Gitsigns stage_hunk<CR>')
map({'n', 'v'}, '<leader>hr', ':Gitsigns reset_hunk<CR>')
map('n', '<leader>hS', gs.stage_buffer)
map('n', '<leader>hu', gs.undo_stage_hunk)
map('n', '<leader>hR', gs.reset_buffer)
map('n', '<leader>hp', gs.preview_hunk)
map('n', '<leader>hb', function() gs.blame_line{full=true} end)
map('n', '<leader>tb', gs.toggle_current_line_blame)
map('n', '<leader>hd', gs.diffthis)
map('n', '<leader>hD', function() gs.diffthis('~') end)
map('n', '<leader>td', gs.toggle_deleted)

-- Text object
map({'o', 'x'}, 'ih', ':<C-U>Gitsigns select_hunk<CR>')
end
}

0 comments on commit ddba281

Please sign in to comment.