1" Vim filetype plugin 2" Language: git commit file 3" Maintainer: Tim Pope <[email protected]> 4" Last Change: 2012 April 7 5 6" Only do this when not done yet for this buffer 7if (exists("b:did_ftplugin")) 8 finish 9endif 10 11runtime! ftplugin/git.vim 12let b:did_ftplugin = 1 13 14setlocal nomodeline 15 16let b:undo_ftplugin = 'setl modeline<' 17 18if &textwidth == 0 19 " make sure that log messages play nice with git-log on standard terminals 20 setlocal textwidth=72 21 let b:undo_ftplugin .= "|setl tw<" 22endif 23 24if exists("g:no_gitcommit_commands") || v:version < 700 25 finish 26endif 27 28if !exists("b:git_dir") 29 let b:git_dir = expand("%:p:h") 30endif 31 32command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0,b:git_dir,<f-args>) 33 34function! s:diffcomplete(A,L,P) 35 let args = "" 36 if a:P <= match(a:L." -- "," -- ")+3 37 let args = args . "-p\n--stat\n--shortstat\n--summary\n--patch-with-stat\n--no-renames\n-B\n-M\n-C\n" 38 end 39 if exists("b:git_dir") && a:A !~ '^-' 40 let tree = fnamemodify(b:git_dir,':h') 41 if strpart(getcwd(),0,strlen(tree)) == tree 42 let args = args."\n".system("git diff --cached --name-only") 43 endif 44 endif 45 return args 46endfunction 47 48function! s:gitdiffcached(bang,gitdir,...) 49 let tree = fnamemodify(a:gitdir,':h') 50 let name = tempname() 51 let git = "git" 52 if strpart(getcwd(),0,strlen(tree)) != tree 53 let git .= " --git-dir=".(exists("*shellescape") ? shellescape(a:gitdir) : '"'.a:gitdir.'"') 54 endif 55 if a:0 56 let extra = join(map(copy(a:000),exists("*shellescape") ? 'shellescape(v:val)' : "'\"'.v:val.'\"'")) 57 else 58 let extra = "-p --stat=".&columns 59 endif 60 call system(git." diff --cached --no-color --no-ext-diff ".extra." > ".(exists("*shellescape") ? shellescape(name) : name)) 61 exe "pedit ".(exists("*fnameescape") ? fnameescape(name) : name) 62 wincmd P 63 let b:git_dir = a:gitdir 64 command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0,b:git_dir,<f-args>) 65 nnoremap <buffer> <silent> q :q<CR> 66 setlocal buftype=nowrite nobuflisted noswapfile nomodifiable filetype=git 67endfunction 68