neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

gitcommit.vim (2078B)


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