summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nvim/nvim/init.lua2
-rw-r--r--nvim/nvim/lua/git.lua45
2 files changed, 47 insertions, 0 deletions
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', '<leader>hs', gitsigns.stage_hunk)
+ map('n', '<leader>hr', gitsigns.reset_hunk)
+ map('v', '<leader>hs', function() gitsigns.stage_hunk {vim.fn.line('.'), vim.fn.line('v')} end)
+ map('v', '<leader>hr', function() gitsigns.reset_hunk {vim.fn.line('.'), vim.fn.line('v')} end)
+ -- map('n', '<leader>hS', gitsigns.stage_buffer)
+ map('n', '<leader>hu', gitsigns.undo_stage_hunk)
+ -- map('n', '<leader>hR', gitsigns.reset_buffer)
+ map('n', '<leader>hp', gitsigns.preview_hunk)
+ map('n', '<leader>hb', function() gitsigns.blame_line{full=true} end)
+ map('n', '<leader>tb', gitsigns.toggle_current_line_blame)
+ map('n', '<leader>hd', gitsigns.diffthis)
+ map('n', '<leader>hD', function() gitsigns.diffthis('~') end)
+ map('n', '<leader>td', gitsigns.toggle_deleted)
+
+ -- Text object
+ map({'o', 'x'}, 'ih', ':<C-U>Gitsigns select_hunk<CR>')
+ end
+})