This repository has been archived on 2024-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
neovim/plugins/git/gitsigns-nvim.lua

52 lines
1.1 KiB
Lua

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,
})