From 4975e76935b70670a25e530f9d1a270bc7d9598b Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Fri, 19 Mar 2010 21:23:41 -0400 Subject: [PATCH] `D` in :Gstatus invokes :Gdiff --- doc/fugitive.txt | 3 ++- plugin/fugitive.vim | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/doc/fugitive.txt b/doc/fugitive.txt index 882e17a..cb437f5 100644 --- a/doc/fugitive.txt +++ b/doc/fugitive.txt @@ -51,7 +51,8 @@ that are part of Git repositories). *fugitive-:Gstatus* :Gstatus Bring up the output of git-status in the preview - window. Press - to stage or unstage the file on the + window. Press D to |:Gdiff| the file on the cursor + line. Press - to stage or unstage the file on the cursor line. Press p to do so on a per hunk basis (--patch). Press C to invoke |:Gcommit|. diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index 75b4ae2..de77391 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -538,6 +538,26 @@ function! fugitive#reload_status() abort endfor endfunction +function! s:StageDiff() abort + let line = getline('.') + let filename = matchstr(line,'^#\t\%([[:alpha:] ]\+: *\)\=\zs.*') + if filename ==# '' + return '' + endif + let section = getline(search('^# .*:$','bnW')) + if line =~# '^#\trenamed:' && filename =~ ' -> ' + let [old, new] = split(filename,' -> ') + execute 'Gedit '.s:fnameescape(':0:'.new) + return 'Gdiff HEAD:'.s:fnameescape(old) + elseif section == '# Changes to be committed:' + execute 'Gedit '.s:fnameescape(':0:'.filename) + return 'Gdiff -' + else + execute 'Gedit '.s:fnameescape('/'.filename) + return 'Gdiff' + endif +endfunction + function! s:StageToggle(lnum1,lnum2) abort try let output = '' @@ -1336,6 +1356,7 @@ function! s:BufReadIndex() setlocal ro noma nomod nomodeline bufhidden=delete nnoremap a :let b:fugitive_display_format += 1exe BufReadIndex() nnoremap i :let b:fugitive_display_format -= 1exe BufReadIndex() + nnoremap D :execute StageDiff() nnoremap - :execute StageToggle(line('.'),line('.')+v:count1-1) xnoremap - :execute StageToggle(line("'<"),line("'>")) nnoremap p :execute StagePatch(line('.'),line('.')+v:count1-1)