You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.5 KiB

  1. return {
  2. "tpope/vim-fugitive",
  3. dependencies = {
  4. "shumphrey/fugitive-gitlab.vim",
  5. },
  6. config = function()
  7. vim.opt.diffopt = vim.opt.diffopt + "vertical"
  8. vim.opt.display = vim.opt.display + "lastline"
  9. local fugitive_augroup = vim.api.nvim_create_augroup("fugitive_mappings", { clear = true })
  10. local function set_fugitive_mappings()
  11. local opts = { noremap = true, silent = true }
  12. vim.api.nvim_buf_set_keymap(0, "n", "<leader>gp", "<cmd>Git push<CR>", opts)
  13. vim.api.nvim_buf_set_keymap(0, "n", "<leader>gP", "<cmd>Git pull<CR>", opts)
  14. vim.api.nvim_buf_set_keymap(0, "n", "<leader>gc", "<cmd>Git commit<CR>", opts)
  15. end
  16. -- Create an autocmd to trigger the function when entering a Fugitive buffer
  17. vim.api.nvim_create_autocmd("FileType", {
  18. group = fugitive_augroup,
  19. pattern = "fugitive",
  20. callback = set_fugitive_mappings,
  21. })
  22. local opts = { noremap = true, silent = true }
  23. vim.keymap.set("n", "<leader>gg", function ()
  24. vim.cmd("Git")
  25. end, opts)
  26. vim.keymap.set("v", "<leader>gl", function()
  27. local startPos = vim.fn.getpos("v")
  28. local endPos = vim.fn.getpos(".")
  29. local startLine = math.min(startPos[2], endPos[2])
  30. local endLine = math.max(startPos[2], endPos[2])
  31. if startLine == 0 or endLine == 0 then
  32. vim.notify(vim.inspect(vim.fn.getpos("'<")) .. " to " .. vim.inspect(vim.fn.getpos("'>")))
  33. return
  34. end
  35. vim.cmd(string.format("Git log -L %d,%d:%s", startLine, endLine, vim.fn.expand("%:.")))
  36. end, opts)
  37. end,
  38. }