]> git.r.bdr.sh - rbdr/dotfiles/blame_incremental - vim/ftplugin/gitcommit.vim
Remove Ag Plugin
[rbdr/dotfiles] / vim / ftplugin / gitcommit.vim
... / ...
CommitLineData
1" Vim filetype plugin
2" Language: git commit file
3" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
4
5" Only do this when not done yet for this buffer
6if (exists("b:did_ftplugin"))
7 finish
8endif
9
10runtime! ftplugin/git.vim
11let b:did_ftplugin = 1
12
13set nomodeline
14
15let b:undo_ftplugin = 'setl modeline<'
16
17if &textwidth == 0
18 " make sure that log messages play nice with git-log on standard terminals
19 setlocal textwidth=72
20 let b:undo_ftplugin .= "|setl tw<"
21endif
22
23if exists("g:no_gitcommit_commands") || v:version < 700
24 finish
25endif
26
27if !exists("b:git_dir")
28 let b:git_dir = expand("%:p:h")
29endif
30
31" Automatically diffing can be done with:
32" autocmd BufRead *.git/COMMIT_EDITMSG DiffGitCached | wincmd p
33command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0,b:git_dir,<f-args>)
34
35function! s:diffcomplete(A,L,P)
36 let args = ""
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"
39 end
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")
44 endif
45 endif
46 return args
47endfunction
48
49function! s:gitdiffcached(bang,gitdir,...)
50 let tree = fnamemodify(a:gitdir,':h')
51 let name = tempname()
52 let git = "git"
53 if strpart(getcwd(),0,strlen(tree)) != tree
54 let git .= " --git-dir=".(exists("*shellescape") ? shellescape(a:gitdir) : '"'.a:gitdir.'"')
55 endif
56 if a:0
57 let extra = join(map(copy(a:000),exists("*shellescape") ? 'shellescape(v:val)' : "'\"'.v:val.'\"'"))
58 else
59 let extra = "-p --stat=".&columns
60 endif
61 call system(git." diff --cached --no-color ".extra." > ".(exists("*shellescape") ? shellescape(name) : name))
62 exe "pedit ".(exists("*fnameescape") ? fnameescape(name) : name)
63 wincmd P
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
68endfunction