return { "tpope/vim-fugitive", event = "VeryLazy", dependencies = { "shumphrey/fugitive-gitlab.vim", }, config = function() vim.opt.diffopt = vim.opt.diffopt + "vertical" vim.opt.display = vim.opt.display + "lastline" local fugitive_augroup = vim.api.nvim_create_augroup("fugitive_mappings", { clear = true }) local function set_fugitive_mappings() local opts = { noremap = true, silent = true } vim.api.nvim_buf_set_keymap(0, "n", "gp", "Git push", opts) vim.api.nvim_buf_set_keymap(0, "n", "gP", "Git pull", opts) vim.api.nvim_buf_set_keymap(0, "n", "gc", "Git commit", opts) end -- Create an autocmd to trigger the function when entering a Fugitive buffer vim.api.nvim_create_autocmd("FileType", { group = fugitive_augroup, pattern = "fugitive", callback = set_fugitive_mappings, }) local opts = { noremap = true, silent = true } vim.keymap.set("n", "gg", function () vim.cmd("Git") end, opts) vim.keymap.set("v", "gl", function() local startPos = vim.fn.getpos("v") local endPos = vim.fn.getpos(".") local startLine = math.min(startPos[2], endPos[2]) local endLine = math.max(startPos[2], endPos[2]) if startLine == 0 or endLine == 0 then vim.notify(vim.inspect(vim.fn.getpos("'<")) .. " to " .. vim.inspect(vim.fn.getpos("'>"))) return end vim.cmd(string.format("Git log -L %d,%d:%s", startLine, endLine, vim.fn.expand("%:."))) end, opts) end, }