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.

46 lines
1.6 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", "<cmd>Git<CR>", opts)
  24. vim.keymap.set("v", "<leader>gl", function()
  25. local startPos = vim.fn.getpos("'<")
  26. local endPos = vim.fn.getpos("'>")
  27. local startLine = startPos[2]
  28. local endLine = endPos[2]
  29. if startLine == 0 or endLine == 0 then
  30. vim.notify(vim.inspect(vim.fn.getpos("'<")) .. " to " .. vim.inspect(vim.fn.getpos("'>")))
  31. return
  32. end
  33. vim.cmd(string.format("Git log -L %d,%d:%s", startLine, endLine, vim.fn.expand("%:.")))
  34. end, opts)
  35. end,
  36. }