diff --git a/README.mkd b/README.mkd index 07f9555..0b49493 100644 --- a/README.mkd +++ b/README.mkd @@ -238,6 +238,11 @@ Finally, you can force vim-gitgutter to update its signs across all visible buff See the customisation section below for how to change the defaults. +### Vimdiff + +Use the `GitGutterDiffOrig` command to open a vimdiff view of the current buffer, respecting `g:gitgutter_diff_relative_to` and `:gitgutter_diff_base`. + + ### Folding Use the `GitGutterFold` command to fold all unchanged lines, leaving just the hunks visible. Use `zr` to unfold 3 lines of context above and below a hunk. diff --git a/autoload/gitgutter.vim b/autoload/gitgutter.vim index ed9c184..bbc1c99 100644 --- a/autoload/gitgutter.vim +++ b/autoload/gitgutter.vim @@ -233,3 +233,29 @@ function! gitgutter#quickfix(current_file) call setloclist(0, locations) endif endfunction + + +function! gitgutter#difforig() + let bufnr = bufnr('') + let path = gitgutter#utility#repo_path(bufnr, 1) + + vertical new + set buftype=nofile + + if g:gitgutter_diff_relative_to ==# 'index' + let index_name = gitgutter#utility#get_diff_base(bufnr).':'.path + let cmd = gitgutter#utility#cd_cmd(bufnr, + \ g:gitgutter_git_executable.' '.g:gitgutter_git_args.' --no-pager show '.index_name + \ ) + " NOTE: this uses &shell to execute cmd. Perhaps we should use instead + " gitgutter#utility's use_known_shell() / restore_shell() functions. + silent! execute "read ++edit !" cmd + else + silent! execute "read ++edit" path + endif + + 0d_ + diffthis + wincmd p + diffthis +endfunction diff --git a/doc/gitgutter.txt b/doc/gitgutter.txt index cfbca4b..3ad150c 100644 --- a/doc/gitgutter.txt +++ b/doc/gitgutter.txt @@ -221,6 +221,12 @@ Commands for folds:~ :GitGutterFold Fold all unchanged lines. Execute again to undo. +Other commands:~ + + *gitgutter-:GitGutterDiffOrig* +:GitGutterDiffOrig Similar to |:DiffOrig| but shows gitgutter's diff. + + =============================================================================== AUTOCOMMANDS *gitgutter-autocommands* diff --git a/plugin/gitgutter.vim b/plugin/gitgutter.vim index ef0bb99..9e989ce 100644 --- a/plugin/gitgutter.vim +++ b/plugin/gitgutter.vim @@ -134,6 +134,8 @@ command! -bar GitGutterBufferToggle call gitgutter#buffer_toggle() command! -bar GitGutterQuickFix call gitgutter#quickfix(0) command! -bar GitGutterQuickFixCurrentFile call gitgutter#quickfix(1) +command! -bar GitGutterDiffOrig call gitgutter#difforig() + " }}} " Line highlights {{{