diff --git a/lua/plugins.lua b/lua/plugins.lua index fd8e739..af852bb 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -40,7 +40,7 @@ pcall(vim.cmd.colorscheme, "gruvbox") -- Simple setup({}) plugins for _, name in ipairs({ "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", }) do pcall(function() require(name).setup() end) @@ -218,6 +218,70 @@ vim.keymap.set("x", "cc", function() silicon_shot(true) end, vim.keymap.set("x", "cs", function() silicon_shot(false) end, { 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 = " , ", + + -- 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 "" + 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 "" + end, "prev hunk", { expr = true }) + + -- Stage/reset. stage_hunk toggles: run it on a staged hunk to unstage. + map("n", "hs", gs.stage_hunk, "stage hunk (toggle)") + map("n", "hr", gs.reset_hunk, "reset hunk") + map("x", "hs", function() gs.stage_hunk({ vim.fn.line("."), vim.fn.line("v") }) end, + "stage selected lines") + map("x", "hr", function() gs.reset_hunk({ vim.fn.line("."), vim.fn.line("v") }) end, + "reset selected lines") + map("n", "hS", gs.stage_buffer, "stage buffer") + map("n", "hR", gs.reset_buffer, "reset buffer") + + -- Inspect + map("n", "hp", gs.preview_hunk, "preview hunk") + map("n", "hi", gs.preview_hunk_inline, "preview hunk inline") + map("n", "hb", function() gs.blame_line({ full = true }) end, "blame line (full)") + map("n", "hB", gs.blame, "blame file") + map("n", "hd", gs.diffthis, "diff against index") + map("n", "hD", function() gs.diffthis("~") end, "diff against last commit") + map("n", "hq", gs.setqflist, "hunks to quickfix") + + -- Toggles + map("n", "htb", gs.toggle_current_line_blame, "toggle inline blame") + map("n", "htd", gs.toggle_deleted, "toggle deleted lines") + map("n", "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" } }) -- Treesitter (main branch: no configs.setup; install parsers manually)