Public Access
gitsigns
This commit is contained in:
+65
-1
@@ -40,7 +40,7 @@ pcall(vim.cmd.colorscheme, "gruvbox")
|
|||||||
-- Simple setup({}) plugins
|
-- Simple setup({}) plugins
|
||||||
for _, name in ipairs({
|
for _, name in ipairs({
|
||||||
"oil", "mini.pick", "mini.extra", "mini.icons", "mason", "typst-preview",
|
"oil", "mini.pick", "mini.extra", "mini.icons", "mason", "typst-preview",
|
||||||
"nvim-autopairs", "gitsigns", "mini.jump",
|
"nvim-autopairs", "mini.jump",
|
||||||
"mini.ai", "nvim-ts-autotag", "todo-comments", "csvview",
|
"mini.ai", "nvim-ts-autotag", "todo-comments", "csvview",
|
||||||
}) do
|
}) do
|
||||||
pcall(function() require(name).setup() end)
|
pcall(function() require(name).setup() end)
|
||||||
@@ -218,6 +218,70 @@ vim.keymap.set("x", "<leader>cc", function() silicon_shot(true) end,
|
|||||||
vim.keymap.set("x", "<leader>cs", function() silicon_shot(false) end,
|
vim.keymap.set("x", "<leader>cs", function() silicon_shot(false) end,
|
||||||
{ desc = "Silicon: save code screenshot to file" })
|
{ desc = "Silicon: save code screenshot to file" })
|
||||||
|
|
||||||
|
require("gitsigns").setup({
|
||||||
|
current_line_blame = true,
|
||||||
|
current_line_blame_opts = { virt_text_pos = "eol", delay = 300, ignore_whitespace = true },
|
||||||
|
current_line_blame_formatter = " <author>, <author_time:%R> — <summary>",
|
||||||
|
|
||||||
|
-- Buffer-local so the maps only exist in git-tracked files.
|
||||||
|
on_attach = function(buf)
|
||||||
|
local gs = require("gitsigns")
|
||||||
|
local function map(mode, lhs, rhs, desc, opts)
|
||||||
|
opts = vim.tbl_extend("force", { buffer = buf, desc = "Git: " .. desc }, opts or {})
|
||||||
|
vim.keymap.set(mode, lhs, rhs, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Navigation. In a diff window, fall back to builtin ]c/[c.
|
||||||
|
map("n", "]c", function()
|
||||||
|
if vim.wo.diff then return "]c" end
|
||||||
|
vim.schedule(function() gs.nav_hunk("next") end)
|
||||||
|
return "<Ignore>"
|
||||||
|
end, "next hunk", { expr = true })
|
||||||
|
map("n", "[c", function()
|
||||||
|
if vim.wo.diff then return "[c" end
|
||||||
|
vim.schedule(function() gs.nav_hunk("prev") end)
|
||||||
|
return "<Ignore>"
|
||||||
|
end, "prev hunk", { expr = true })
|
||||||
|
|
||||||
|
-- Stage/reset. stage_hunk toggles: run it on a staged hunk to unstage.
|
||||||
|
map("n", "<leader>hs", gs.stage_hunk, "stage hunk (toggle)")
|
||||||
|
map("n", "<leader>hr", gs.reset_hunk, "reset hunk")
|
||||||
|
map("x", "<leader>hs", function() gs.stage_hunk({ vim.fn.line("."), vim.fn.line("v") }) end,
|
||||||
|
"stage selected lines")
|
||||||
|
map("x", "<leader>hr", function() gs.reset_hunk({ vim.fn.line("."), vim.fn.line("v") }) end,
|
||||||
|
"reset selected lines")
|
||||||
|
map("n", "<leader>hS", gs.stage_buffer, "stage buffer")
|
||||||
|
map("n", "<leader>hR", gs.reset_buffer, "reset buffer")
|
||||||
|
|
||||||
|
-- Inspect
|
||||||
|
map("n", "<leader>hp", gs.preview_hunk, "preview hunk")
|
||||||
|
map("n", "<leader>hi", gs.preview_hunk_inline, "preview hunk inline")
|
||||||
|
map("n", "<leader>hb", function() gs.blame_line({ full = true }) end, "blame line (full)")
|
||||||
|
map("n", "<leader>hB", gs.blame, "blame file")
|
||||||
|
map("n", "<leader>hd", gs.diffthis, "diff against index")
|
||||||
|
map("n", "<leader>hD", function() gs.diffthis("~") end, "diff against last commit")
|
||||||
|
map("n", "<leader>hq", gs.setqflist, "hunks to quickfix")
|
||||||
|
|
||||||
|
-- Toggles
|
||||||
|
map("n", "<leader>htb", gs.toggle_current_line_blame, "toggle inline blame")
|
||||||
|
map("n", "<leader>htd", gs.toggle_deleted, "toggle deleted lines")
|
||||||
|
map("n", "<leader>htw", gs.toggle_word_diff, "toggle word diff")
|
||||||
|
|
||||||
|
-- Hunk textobject: `dih`, `vih`, ...
|
||||||
|
map({ "o", "x" }, "ih", gs.select_hunk, "select hunk")
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Start commit messages in insert mode with the cursor on line 1.
|
||||||
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
|
pattern = "gitcommit",
|
||||||
|
callback = function(ev)
|
||||||
|
vim.bo[ev.buf].textwidth = 72
|
||||||
|
vim.wo.spell = true
|
||||||
|
vim.cmd("startinsert")
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
require("lualine").setup({ options = { theme = "gruvbox_dark" } })
|
require("lualine").setup({ options = { theme = "gruvbox_dark" } })
|
||||||
|
|
||||||
-- Treesitter (main branch: no configs.setup; install parsers manually)
|
-- Treesitter (main branch: no configs.setup; install parsers manually)
|
||||||
|
|||||||
Reference in New Issue
Block a user