commit e674a7e2f3626ad22178efabd663e004064f951d (tree)
parent b8b5272577eed64dae7806d37ca25360eca24082
Author: Tim Pope <code@tpope.net>
Date: Fri, 19 Aug 2011 15:13:44 -0400
Map dp to show diff in :Gstatus
Closes #101
Diffstat:
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git 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
@@ -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 <buffer> <silent> dd :<C-U>execute <SID>StageDiff('Gvdiff')<CR>
nnoremap <buffer> <silent> dh :<C-U>execute <SID>StageDiff('Gsdiff')<CR>
nnoremap <buffer> <silent> ds :<C-U>execute <SID>StageDiff('Gsdiff')<CR>
+ nnoremap <buffer> <silent> dp :<C-U>execute <SID>StageDiffEdit()<CR>
nnoremap <buffer> <silent> dv :<C-U>execute <SID>StageDiff('Gvdiff')<CR>
nnoremap <buffer> <silent> p :<C-U>execute <SID>StagePatch(line('.'),line('.')+v:count1-1)<CR>
xnoremap <buffer> <silent> p :<C-U>execute <SID>StagePatch(line("'<"),line("'>"))<CR>