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.

49 lines
1.5 KiB

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