gitcommit.vim 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. " Vim filetype plugin
  2. " Language: git commit file
  3. " Maintainer: Tim Pope <vimNOSPAM@tpope.org>
  4. " Last Change: 2022 Jan 05
  5. " Only do this when not done yet for this buffer
  6. if (exists("b:did_ftplugin"))
  7. finish
  8. endif
  9. let b:did_ftplugin = 1
  10. setlocal nomodeline tabstop=8 formatoptions+=tl textwidth=72
  11. setlocal formatoptions-=c formatoptions-=r formatoptions-=o formatoptions-=q formatoptions+=n
  12. setlocal formatlistpat+=\\\|^\\s*[-*+]\\s\\+
  13. setlocal include=^+++
  14. setlocal includeexpr=substitute(v:fname,'^[bi]/','','')
  15. let b:undo_ftplugin = 'setl modeline< tabstop< formatoptions< tw< com< cms< formatlistpat< inc< inex<'
  16. let s:l = search('\C\m^[#;@!$%^&|:] -\{24,\} >8 -\{24,\}$', 'cnW', '', 100)
  17. let &l:comments = ':' . (matchstr(getline(s:l ? s:l : '$'), '^[#;@!$%^&|:]\S\@!') . '#')[0]
  18. let &l:commentstring = &l:comments[1] . ' %s'
  19. unlet s:l
  20. if exists("g:no_gitcommit_commands")
  21. finish
  22. endif
  23. command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0, <f-args>)
  24. let b:undo_ftplugin = b:undo_ftplugin . "|delc DiffGitCached"
  25. function! s:diffcomplete(A, L, P) abort
  26. let args = ""
  27. if a:P <= match(a:L." -- "," -- ")+3
  28. let args = args . "-p\n--stat\n--shortstat\n--summary\n--patch-with-stat\n--no-renames\n-B\n-M\n-C\n"
  29. end
  30. if a:A !~ '^-' && !empty(getftype('.git'))
  31. let args = args."\n".system("git diff --cached --name-only")
  32. endif
  33. return args
  34. endfunction
  35. function! s:gitdiffcached(bang, ...) abort
  36. let name = tempname()
  37. if a:0
  38. let extra = join(map(copy(a:000), 'shellescape(v:val)'))
  39. else
  40. let extra = "-p --stat=".&columns
  41. endif
  42. call system("git diff --cached --no-color --no-ext-diff ".extra." > ".shellescape(name))
  43. exe "pedit " . fnameescape(name)
  44. wincmd P
  45. command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0, <f-args>)
  46. setlocal buftype=nowrite nobuflisted noswapfile nomodifiable filetype=git
  47. endfunction