vim-plug
vim-plug copied to clipboard
fugitive compatibility for viewing commits in PlugDiff
In :PlugDiff, it's possible to hit enter on a given commit to view its content:
fugitive.vim has a very similar feature for viewing commits, but with extra features like being able to browse to other commits and files, and with rhubarb.vim and others, to open the equivalent forge URL e.g. on GitHub.
It'd be cool if vim-plug used fugitive to view commits when it's available.
NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1703358377
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.9.5/share/nvim"
- Type:
- [ ] Bug
- [x] Enhancement
- [x] Feature Request
- [ ] Question
- OS:
- [x] All/Other
- [ ] Linux
- [ ] macOS
- [ ] Windows
- Vim:
- [x] Terminal Vim
- [x] GVim
- [x] Neovim
Need some more testing, but this should do the trick.
diff --git a/plug.vim b/plug.vim
index 940811a..4c3a081 100644
--- a/plug.vim
+++ b/plug.vim
@@ -2683,6 +2683,11 @@ function! s:preview_commit()
return
endif
+ let use_fugitive = exists('*FugitiveFind') && len(sha)
+ if use_fugitive
+ let title = FugitiveFind(sha, g:plugs[name].dir . '/.git')
+ endif
+
if !s:is_preview_window_open()
execute get(g:, 'plug_pwindow', 'vertical rightbelow new')
execute 'e' title
@@ -2691,6 +2696,12 @@ function! s:preview_commit()
wincmd P
endif
setlocal previewwindow filetype=git buftype=nofile bufhidden=wipe nobuflisted modifiable
+ nnoremap <silent> <buffer> q :q<cr>
+ if use_fugitive
+ wincmd p
+ return
+ endif
+
let batchfile = ''
try
let [sh, shellcmdflag, shrd] = s:chsh(1)
@@ -2706,7 +2717,6 @@ function! s:preview_commit()
endif
endtry
setlocal nomodifiable
- nnoremap <silent> <buffer> q :q<cr>
wincmd p
endfunction
The patch works. But it's considerably slower to open a commit, so users who don't need additional features of Fugitive may not like it.