2 " Language: git commit file
3 " Maintainer: Tim Pope <vimNOSPAM@tpope.org>
5 " Only do this when not done yet for this buffer
6 if (exists("b:did_ftplugin"))
10 runtime! ftplugin/git.vim
11 let b:did_ftplugin = 1
15 let b:undo_ftplugin = 'setl modeline<'
18 " make sure that log messages play nice with git-log on standard terminals
20 let b:undo_ftplugin .= "|setl tw<"
23 if exists("g:no_gitcommit_commands") || v:version < 700
27 if !exists("b:git_dir")
28 let b:git_dir = expand("%:p:h")
31 " Automatically diffing can be done with:
32 " autocmd BufRead *.git/COMMIT_EDITMSG DiffGitCached | wincmd p
33 command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0,b:git_dir,<f-args>)
35 function! s:diffcomplete(A,L,P)
37 if a:P <= match(a:L." -- "," -- ")+3
38 let args = args . "-p\n--stat\n--shortstat\n--summary\n--patch-with-stat\n--no-renames\n-B\n-M\n-C\n"
40 if exists("b:git_dir") && a:A !~ '^-'
41 let tree = fnamemodify(b:git_dir,':h')
42 if strpart(getcwd(),0,strlen(tree)) == tree
43 let args = args."\n".system("git diff --cached --name-only")
49 function! s:gitdiffcached(bang,gitdir,...)
50 let tree = fnamemodify(a:gitdir,':h')
53 if strpart(getcwd(),0,strlen(tree)) != tree
54 let git .= " --git-dir=".(exists("*shellescape") ? shellescape(a:gitdir) : '"'.a:gitdir.'"')
57 let extra = join(map(copy(a:000),exists("*shellescape") ? 'shellescape(v:val)' : "'\"'.v:val.'\"'"))
59 let extra = "-p --stat=".&columns
61 call system(git." diff --cached --no-color ".extra." > ".(exists("*shellescape") ? shellescape(name) : name))
62 exe "pedit ".(exists("*fnameescape") ? fnameescape(name) : name)
64 let b:git_dir = a:gitdir
65 command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0,b:git_dir,<f-args>)
66 nnoremap <silent> q :q<CR>
67 setlocal buftype=nowrite nobuflisted noswapfile nomodifiable filetype=git