1
Fork 0

Set up gitsigns

This commit is contained in:
Matei Adriel 2023-11-10 17:28:14 +01:00
parent 63a97e5870
commit 18abc39e9c
No known key found for this signature in database
6 changed files with 124 additions and 10 deletions
dotfiles/neovim/lua/my/plugins

View file

@ -0,0 +1,100 @@
local env = require("my.helpers.env")
local M = {
"lewis6991/gitsigns.nvim",
event = "BufReadPost",
cond = env.firenvim.not_active() and env.vscode.not_active(),
config = function()
require("gitsigns").setup({
on_attach = function(bufnr)
local wk = require("which-key")
local gs = package.loaded.gitsigns
-- {{{ Helpers
local function map(mode, from, to, desc, expr)
vim.keymap.set(
mode,
from,
to,
{ expr = expr, silent = true, buffer = bufnr, desc = desc }
)
end
local function exprmap(from, to, desc)
map("n", from, to, desc, true)
end
-- }}}
-- {{{ Navigation
exprmap("]c", function()
if vim.wo.diff then
return "]c"
end
vim.schedule(function()
gs.next_hunk()
end)
return "<Ignore>"
end, "Navigate to next hunk")
exprmap("[c", function()
if vim.wo.diff then
return "[c"
end
vim.schedule(function()
gs.prev_hunk()
end)
return "<Ignore>"
end, "Navigate to previous hunk")
-- }}}
-- {{{ Actions
local prefix = "<leader>h"
wk.register({
[prefix] = { name = "gitsigns" },
})
-- {{{ Normal mode
map("n", prefix .. "s", gs.stage_hunk, "[s]tage hunk")
map("n", prefix .. "r", gs.reset_hunk, "[r]eset hunk")
map("n", prefix .. "S", gs.stage_buffer, "[s]tage buffer")
map("n", prefix .. "u", gs.undo_stage_hunk, "[u]ndo hunk staging")
map("n", prefix .. "R", gs.reset_buffer, "[r]eset buffer")
map("n", prefix .. "p", gs.preview_hunk, "[p]review hunk")
map("n", prefix .. "b", function()
gs.blame_line({ full = true })
end, "[b]lame line")
map("n", prefix .. "d", gs.diffthis, "[d]iff this")
map("n", prefix .. "D", function()
gs.diffthis("~")
end, "[d]iff file (?)")
-- }}}
-- {{{ Toggles
map(
"n",
prefix .. "tb",
gs.toggle_current_line_blame,
"[t]oggle line [b]laming"
)
map("n", prefix .. "td", gs.toggle_deleted, "[t]oggle [d]eleted")
-- }}}
-- {{{ Visual
map("v", prefix .. "s", function()
gs.stage_hunk({ vim.fn.line("."), vim.fn.line("v") })
end, "stage visual hunk")
map("v", prefix .. "r", function()
gs.reset_hunk({ vim.fn.line("."), vim.fn.line("v") })
end, "reset visual hunk")
-- }}}
-- }}}
-- {{{ Text objects
map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>", "Inside hunk")
-- }}}
end,
})
end,
}
return M

View file

@ -9,7 +9,7 @@ local function bindHarpoon(key, index)
end
function M.init()
vim.keymap.set("n", "<leader>h", function()
vim.keymap.set("n", "<leader>H", function()
require("harpoon.mark").add_file()
end, { desc = "Add file to [h]arpoon" })
vim.keymap.set("n", "<C-a>", function()

View file

@ -66,19 +66,19 @@ local M = {
set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = {
["]f"] = "@function.outer",
["]c"] = "@class.outer",
["]t"] = "@class.outer",
},
goto_next_end = {
["]F"] = "@function.outer",
["]C"] = "@class.outer",
["]T"] = "@class.outer",
},
goto_previous_start = {
["[f"] = "@function.outer",
["[c"] = "@class.outer",
["[t"] = "@class.outer",
},
goto_previous_end = {
["[F"] = "@function.outer",
["[C"] = "@class.outer",
["[T"] = "@class.outer",
},
},
--}}}