Update gitsigns configuration

- Remove use of `pcall` to simplify requiring the plugin.
- Replace usages of custom keybinding functions with `vim.keymap.set()`.
This commit is contained in:
Oliver Davies 2024-05-16 17:46:45 +01:00
parent e7bcf62062
commit 085a54aefc

View file

@ -1,40 +1,30 @@
local gitsigns_status_ok, gitsigns = pcall(require, "gitsigns")
if not gitsigns_status_ok then
return
end
local gitsigns = require "gitsigns"
gitsigns.setup {
linehl = false,
numhl = true,
}
local map = require("opdavies.keymap").map
local nmap = require("opdavies.keymap").nmap
local vmap = require("opdavies.keymap").vmap
local set = vim.keymap.set
nmap { "[h", "<cmd>Gitsigns prev_hunk<CR>" }
nmap { "]h", "<cmd>Gitsigns next_hunk<CR>" }
set("n", "[h", "<cmd>Gitsigns prev_hunk<CR>")
set("n", "]h", "<cmd>Gitsigns next_hunk<CR>")
nmap { "<leader>hR", gitsigns.reset_buffer }
nmap { "<leader>hS", gitsigns.stage_buffer }
nmap { "<leader>hb", gitsigns.blame_line }
nmap { "<leader>hp", gitsigns.preview_hunk }
nmap { "<leader>hr", gitsigns.reset_hunk }
nmap { "<leader>hs", gitsigns.stage_hunk }
nmap { "<leader>hu", gitsigns.undo_stage_hunk }
set("n", "<leader>hR", gitsigns.reset_buffer)
set("n", "<leader>hS", gitsigns.stage_buffer)
set("n", "<leader>hb", gitsigns.blame_line)
set("n", "<leader>hp", gitsigns.preview_hunk)
set("n", "<leader>hr", gitsigns.reset_hunk)
set("n", "<leader>hs", gitsigns.stage_hunk)
set("n", "<leader>hu", gitsigns.undo_stage_hunk)
vmap {
"<leader>hr",
function()
gitsigns.reset_hunk { vim.fn.line ".", vim.fn.line "v" }
end,
}
vmap {
"<leader>hs",
function()
gitsigns.stage_hunk { vim.fn.line ".", vim.fn.line "v" }
end,
}
set("v", "<leader>hr", function()
gitsigns.reset_hunk { vim.fn.line ".", vim.fn.line "v" }
end)
set("v", "<leader>hs", function()
gitsigns.stage_hunk { vim.fn.line ".", vim.fn.line "v" }
end)
-- Text object.
map { { "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>" }
set({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>")