git.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. local MiniDiff = require('mini.diff')
  2. local util = require('user.util')
  3. -- shows added/removed/changed lines
  4. MiniDiff.setup({
  5. -- keymap #bracketed
  6. -- ]h / [h - navigate by hunks
  7. view = {
  8. style = 'sign',
  9. signs = {
  10. delete = '_',
  11. },
  12. },
  13. source = {
  14. MiniDiff.gen_source.git(),
  15. -- handle fugitive paths
  16. {
  17. name = 'fugitive',
  18. attach = function(buf_id)
  19. local resolved = util.resolve_git_path(buf_id)
  20. if not resolved or resolved.path == '' then
  21. return false
  22. end
  23. local source = vim.fn.FugitiveFind(string.format('%s~1:%s', resolved.commit, resolved.path))
  24. local text = vim.fn['fugitive#readfile'](source)
  25. MiniDiff.set_ref_text(buf_id, text)
  26. end
  27. }
  28. }
  29. })
  30. -- open status in current split without special flag (so navigating away closes it)
  31. -- https://github.com/tpope/vim-fugitive/issues/1296
  32. vim.keymap.set('n', '<Leader>gs', '<cmd>Gedit :<CR>')
  33. vim.keymap.set('n', '<Leader>gb', '<cmd>Telescope git_branches<CR>')
  34. vim.keymap.set('n', '<Leader>gd', MiniDiff.toggle_overlay)
  35. -- conflicts navigation #bracketed
  36. vim.keymap.set('n', '[x', '?^[<lt>=>]\\{7}<CR>')
  37. vim.keymap.set('n', ']x', '/^[<lt>=>]\\{7}<CR>')