plugin/git: add gitsigns nvim plugin

This commit is contained in:
Dmitriy Pleshevskiy 2022-09-18 16:32:54 +03:00
parent 3d704b32d0
commit 4354e3ce00
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
3 changed files with 60 additions and 0 deletions

View file

@ -16,6 +16,7 @@ let
plugins = callPlugins [ plugins = callPlugins [
./plugins/syntax ./plugins/syntax
./plugins/git
./plugins/explorer ./plugins/explorer
(import ./plugins/theme { (import ./plugins/theme {
inherit enableBarBar enableDevIcons; inherit enableBarBar enableDevIcons;

7
plugins/git/default.nix Normal file
View file

@ -0,0 +1,7 @@
{ gitsigns-nvim, ... }:
{
luaConfig = builtins.readFile ./gitsigns-nvim.lua;
plugins = [ gitsigns-nvim ];
}

View file

@ -0,0 +1,52 @@
function on_attach(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", "]h", function()
if vim.wo.diff then
return "]h"
end
vim.schedule(function()
gs.next_hunk()
end)
return "<Ignore>"
end, { expr = true })
map("n", "[h", function()
if vim.wo.diff then
return "[h"
end
vim.schedule(function()
gs.prev_hunk()
end)
return "<Ignore>"
end, { expr = true })
-- Actions
map({ "n", "v" }, "<leader>gs", ":Gitsigns stage_hunk<CR>")
map({ "n", "v" }, "<leader>gr", ":Gitsigns reset_hunk<CR>")
map("n", "<leader>gu", gs.undo_stage_hunk)
map("n", "<leader>gp", gs.preview_hunk)
map("n", "<leader>gb", function()
gs.blame_line({ full = true })
end)
map("n", "<leader>gtb", gs.toggle_current_line_blame)
map("n", "<leader>gd", gs.diffthis)
map("n", "<leader>gD", function()
gs.diffthis("~")
end)
-- Text object
map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>")
end
-- See: https://github.com/lewis6991/gitsigns.nvim
require("gitsigns").setup({
on_attach = on_attach,
})