summaryrefslogtreecommitdiff
path: root/lua/config/plugins/git.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/config/plugins/git.lua')
-rw-r--r--lua/config/plugins/git.lua81
1 files changed, 81 insertions, 0 deletions
diff --git a/lua/config/plugins/git.lua b/lua/config/plugins/git.lua
new file mode 100644
index 0000000..5502ce7
--- /dev/null
+++ b/lua/config/plugins/git.lua
@@ -0,0 +1,81 @@
+return {
+ {
+ "lewis6991/gitsigns.nvim",
+ config = function()
+ local gitsigns = require("gitsigns")
+
+ gitsigns.setup({
+ signs_staged_enable = true,
+ signcolumn = true,
+ numhl = true,
+ linehl = false,
+ word_diff = false,
+ watch_gitdir = {
+ follow_files = true
+ },
+ auto_attach = true,
+ attach_to_untracked = false,
+ current_line_blame = false,
+ current_line_blame_opts = {
+ virt_text = true,
+ virt_text_pos = "eol",
+ delay = 1000,
+ ignore_whitespace = false,
+ virt_text_priority = 100,
+ use_focus = true,
+ },
+ current_line_blame_formatter = "<author>, <author_time:%R> - <summary>",
+ sign_priority = 6,
+ update_debounce = 100,
+ status_formatter = nil,
+ max_file_length = 40000, -- Disable if file is longer than this (in lines)
+ preview_config = {
+ border = "none",
+ style = "minimal",
+ relative = "cursor",
+ row = 0,
+ col = 1,
+ },
+
+ on_attach = function(bufnr)
+ local function map(mode, l, r, opts)
+ opts = opts or {}
+ opts.buffer = bufnr
+ vim.keymap.set(mode, l, r, opts)
+ end
+
+ -- Navigation
+ map("n", "]c", function()
+ if vim.wo.diff then
+ vim.cmd.normal({ "]c", bang = true })
+ else
+ gitsigns.nav_hunk("next", { target = "all" })
+ end
+ end, { desc = "Goto next change" })
+
+ map("n", "[c", function()
+ if vim.wo.diff then
+ vim.cmd.normal({ "[c", bang = true })
+ else
+ gitsigns.nav_hunk("prev", { target = "all" })
+ end
+ end, { desc = "Goto previous change" })
+
+ -- Actions
+ map("n", "<Leader>ga", gitsigns.stage_hunk, { desc = "stages the current block of changes to git" })
+ map("n", "<Leader>gu", gitsigns.undo_stage_hunk, { desc = "undo the last (git) staged change" })
+ map("n", "<Leader>gp", gitsigns.preview_hunk, { desc = "show the git diff for the current change block" })
+
+ map("n", "<Leader>gb", gitsigns.blame, { desc = "git blame for the whole file" })
+ map("n", "<Leader>gl", gitsigns.blame_line, { desc = "git blame for the current line" })
+
+ map("n", "<Leader>gh", gitsigns.toggle_linehl, { desc = "toggle git diff highlight by line" })
+ map("n", "<Leader>gw", gitsigns.toggle_word_diff, { desc = "toggle git diff highlight by word" })
+
+ -- Text object
+ map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>")
+ end,
+ })
+ end,
+ },
+}