gitcommit.vim 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. " Vim filetype plugin
  2. " Language: git commit file
  3. " Maintainer: Tim Pope <vimNOSPAM@tpope.org>
  4. " Last Change: 2023 Dec 28
  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*\\d\\+[\\]:.)}]\\s\\+\\\|^\\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:setupdiff() abort
  36. command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0, <f-args>)
  37. setlocal buftype=nowrite nobuflisted noswapfile nomodifiable filetype=git
  38. endfunction
  39. function! s:gitdiffcached(bang, ...) abort
  40. let name = tempname()
  41. if a:0
  42. let extra = join(map(copy(a:000), 'shellescape(v:val)'))
  43. else
  44. let extra = "-p --stat=".&columns
  45. endif
  46. call system("git diff --cached --no-color --no-ext-diff ".extra." > ".shellescape(name))
  47. exe 'pedit +call\ s:setupdiff()' fnameescape(name)
  48. silent! wincmd P
  49. endfunction