From e674a7e2f3626ad22178efabd663e004064f951d Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Fri, 19 Aug 2011 15:13:44 -0400 Subject: [PATCH] Map dp to show diff in :Gstatus Closes #101 --- doc/fugitive.txt | 2 ++ plugin/fugitive.vim | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/doc/fugitive.txt b/doc/fugitive.txt index d9658ed..80fe916 100644 --- a/doc/fugitive.txt +++ b/doc/fugitive.txt @@ -42,6 +42,8 @@ that are part of Git repositories). C |:Gcommit| D |:Gdiff| ds |:Gsdiff| + dp |:Git!| diff (mnemonic: p for patch) + dp |:Git| add --intent-to-add (untracked files) dv |:Gvdiff| O |:Gtabedit| o |:Gsplit| diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index 247ac5f..2113b65 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -577,18 +577,18 @@ function! fugitive#reload_status() abort endfunction function! s:StageDiff(diff) abort - let section = getline(search('^# .*:$','bnW')) + let section = getline(search('^# .*:$','bcnW')) let line = getline('.') let filename = matchstr(line,'^#\t\%([[:alpha:] ]\+: *\)\=\zs.\{-\}\ze\%( (new commits)\)\=$') - if filename ==# '' && section == '# Changes to be committed:' + if filename ==# '' && section ==# '# Changes to be committed:' return 'Git diff --cached' elseif filename ==# '' return 'Git diff' - elseif line =~# '^#\trenamed:' && filename =~ ' -> ' + elseif line =~# '^#\trenamed:' && filename =~# ' -> ' let [old, new] = split(filename,' -> ') execute 'Gedit '.s:fnameescape(':0:'.new) return a:diff.' HEAD:'.s:fnameescape(old) - elseif section == '# Changes to be committed:' + elseif section ==# '# Changes to be committed:' execute 'Gedit '.s:fnameescape(':0:'.filename) return a:diff.' -' else @@ -597,6 +597,20 @@ function! s:StageDiff(diff) abort endif endfunction +function! s:StageDiffEdit() abort + let section = getline(search('^# .*:$','bcnW')) + let line = getline('.') + let filename = matchstr(line,'^#\t\%([[:alpha:] ]\+: *\)\=\zs.\{-\}\ze\%( (new commits)\)\=$') + let args = (filename ==# '' ? '.' : s:shellesc(filename)) + if section ==# '# Changes to be committed:' + return 'Git! diff --cached '.args + elseif section ==# '# Untracked files:' + return 'Git add -N '.args + else + return 'Git! diff '.args + endif +endfunction + function! s:StageToggle(lnum1,lnum2) abort try let output = '' @@ -1755,6 +1769,7 @@ function! s:BufReadIndex() nnoremap dd :execute StageDiff('Gvdiff') nnoremap dh :execute StageDiff('Gsdiff') nnoremap ds :execute StageDiff('Gsdiff') + nnoremap dp :execute StageDiffEdit() nnoremap dv :execute StageDiff('Gvdiff') nnoremap p :execute StagePatch(line('.'),line('.')+v:count1-1) xnoremap p :execute StagePatch(line("'<"),line("'>"))