plugin/git: add gitsigns nvim plugin
This commit is contained in:
parent
3d704b32d0
commit
4354e3ce00
3 changed files with 60 additions and 0 deletions
|
@ -16,6 +16,7 @@ let
|
|||
|
||||
plugins = callPlugins [
|
||||
./plugins/syntax
|
||||
./plugins/git
|
||||
./plugins/explorer
|
||||
(import ./plugins/theme {
|
||||
inherit enableBarBar enableDevIcons;
|
||||
|
|
7
plugins/git/default.nix
Normal file
7
plugins/git/default.nix
Normal file
|
@ -0,0 +1,7 @@
|
|||
{ gitsigns-nvim, ... }:
|
||||
|
||||
{
|
||||
luaConfig = builtins.readFile ./gitsigns-nvim.lua;
|
||||
|
||||
plugins = [ gitsigns-nvim ];
|
||||
}
|
52
plugins/git/gitsigns-nvim.lua
Normal file
52
plugins/git/gitsigns-nvim.lua
Normal 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,
|
||||
})
|
Reference in a new issue