open-gitdiff.vim opens git diff using quickfix, fzf, vim-quickui, ...
Require vim8+
Install using vim-plug
" optional dependencies
Plug 'junegunn/fzf'
Plug 'skywind3000/vim-quickui'
" command completion for :GitDiff2Paths
Plug 'tpope/vim-fugitive'
Plug 'jiangyinzuo/open-gitdiff.vim'
let g:open_gitdiff_exclude_patterns = ['\.pdf$', '\.jpg$', '\.png$']
let g:open_gitdiff_qf_nmaps = {'open': '<leader>df', 'next': '<leader>dn', 'prev': '<leader>dp'}
let command_def = 'command -nargs=* '
if v:version >= 901
" open_gitdiff#comp#Complete is implemented with vim9class
let command_def .= '-complete=custom,open_gitdiff#comp#Complete '
endif
exe command_def . 'GitDiffAll call open_gitdiff#OpenAllDiffs(<f-args>)'
exe command_def . 'GitDiffThisTab call open_gitdiff#OpenDiff("tabnew", <f-args>)'
exe command_def . 'GitDiffThis call open_gitdiff#OpenDiff("enew", <f-args>)'
exe command_def . 'FZFGitDiffTab call open_gitdiff#select("tabnew", function("open_gitdiff#fzf#view"), <f-args>)'
exe command_def . 'FZFGitDiff call open_gitdiff#select("enew", function("open_gitdiff#fzf#view"), <f-args>)'
exe command_def . 'QuickUIGitDiffTab call open_gitdiff#select("tabnew", function("open_gitdiff#quickui#listbox#view"), <f-args>)'
exe command_def . 'QuickUIGitDiff call open_gitdiff#select("enew", function("open_gitdiff#quickui#listbox#view"), <f-args>)'
exe command_def . 'QfGitDiff call open_gitdiff#select("enew", function("open_gitdiff#quickfix#view"), <f-args>)'
command -nargs=+ -complete=customlist,fugitive#LogComplete GitDiff2Paths call open_gitdiff#open_diff_by_path(<f-args>)
The above commands accept 0-N arguments, which are passed to git diff
command. <commit>
, <commit>..<commit>
or --cached
--staged
can be
used (see git-diff docs). The following <f-args>
are valid:
" Commands can be replaced to any command defined above.
:QuickUIGitDiffTab
:QuickUIGitDiffTab path/to/file
:QuickUIGitDiffTab HEAD~1 HEAD
:QuickUIGitDiffTab HEAD~1
:QuickUIGitDiffTab HEAD~1..
:QuickUIGitDiffTab HEAD~2..HEAD~1
:QuickUIGitDiffTab --staged
:QuickUIGitDiffTab --staged master
:QuickUIGitDiffTab master --cached
:QuickUIGitDiffTab master --cached -- path/to/file
You can customize git diff command with g:open_gitdiff_cmd
:
" default git diff command
let g:open_gitdiff_cmd = 'git diff --name-status -C'
" the following values are also valid
" let g:open_gitdiff_cmd = 'git diff --name-status'
" let g:open_gitdiff_cmd = 'git diff --name-only'
:GitDiffAll
opens all git diffs.
:GitDiffThisTab
opens the current file in new tab.
:GitDiffThis
opens the current file in current window.
:GitDiff2Paths
opens and diffs the two paths in current window.
:FZFGitDiffTab
lists git diff
in fzf window, then open the selected
diff in new tab.
:FZFGitDiff
lists git diff
in fzf window, then open the selected
diff in current window.
You can customize fzf window option with g:open_gitdiff_fzf_window
:
" default value
let g:open_gitdiff_fzf_window = { 'width': 0.8, 'height': 0.7 }
Enable fzf preview (require python3 in $PATH
):
" default value
let g:open_gitdiff_fzf_preview = 1
:QuickUIGitDiffTab
lists git diff
in vim-quickui listbox, then open the
selected diff in new tab.
:QuickUIGitDiff
lists git diff
in vim-quickui listbox, then open the
selected diff in current window.
:QfGitDiff
lists git diff
in quickfix, then open the selected diff in
current window.
You can use g:open_gitdiff_qf_nmaps
to customize the keymaps in quickfix
window for opening git diffs.
In gitdiff buffer, :OpenFile
/:OpenFileTab
/:OpenFileVsp
/:OpenFileTop
can
open the origin file and lcd to git rev-parse --show-toplevel
.
You can use :diffthis
after :OpenFileVsp
or :OpenFileTop
.
:BDelAllGitdiffs
You can define your own viewer function with open_gitdiff#open_diff
function.
The viewer function has 3 parameters:
function MyViewer(gitcmd, arglist, prompt)
endfunction
gitcmd
is a string that stores the git diff
command, may be 'git diff --name-status -C HEAD~1 HEAD'
.
arglist
is a list that stores the arguments of git diff
command, may be ['HEAD~1', 'HEAD']
.
prompt
is a string that can be used as a title. The possible value may be'HEAD~1..HEAD'
.
See autoload/open_gitdiff/fzf.vim
, autoload/open_gitdiff/quickfix.vim
and autoload/open_gitdiff/quickui/listbox.vim
as examples.
open_gitdiff#open_diff(line)
parses the {line} and opens git diff.
line
should be a output line of git diff --name-status
or git diff --name-only
.
Issues and pull requests for new viewer are welcomed.
:h open-gitdiff-vim