Map dp to show diff in :Gstatus

Closes #101
This commit is contained in:
Tim Pope 2011-08-19 15:13:44 -04:00
parent b8b5272577
commit e674a7e2f3
2 changed files with 21 additions and 4 deletions

View File

@ -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|

View File

@ -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>