gitrebase.vim 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. " Vim filetype plugin
  2. " Language: git rebase --interactive
  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. let &l:comments = ':' . (matchstr(getline('$'), '^[#;@!$%^&|:]\S\@!') . '#')[0]
  11. let &l:commentstring = &l:comments[1] . ' %s'
  12. setlocal formatoptions-=t
  13. setlocal nomodeline
  14. let b:undo_ftplugin = "setl com< cms< fo< ml<"
  15. function! s:choose(word) abort
  16. s/^\(\w\+\>\)\=\(\s*\)\ze\x\{4,40\}\>/\=(strlen(submatch(1)) == 1 ? a:word[0] : a:word) . substitute(submatch(2),'^$',' ','')/e
  17. endfunction
  18. function! s:cycle(count) abort
  19. let words = ['pick', 'edit', 'fixup', 'squash', 'reword', 'drop']
  20. let index = index(map(copy(words), 'v:val[0]'), getline('.')[0])
  21. let index = ((index < 0 ? 0 : index) + 10000 * len(words) + a:count) % len(words)
  22. call s:choose(words[index])
  23. endfunction
  24. command! -buffer -bar -range Pick :<line1>,<line2>call s:choose('pick')
  25. command! -buffer -bar -range Squash :<line1>,<line2>call s:choose('squash')
  26. command! -buffer -bar -range Edit :<line1>,<line2>call s:choose('edit')
  27. command! -buffer -bar -range Reword :<line1>,<line2>call s:choose('reword')
  28. command! -buffer -bar -range Fixup :<line1>,<line2>call s:choose('fixup')
  29. command! -buffer -bar -range Drop :<line1>,<line2>call s:choose('drop')
  30. command! -buffer -count=1 -bar -bang Cycle call s:cycle(<bang>0 ? -<count> : <count>)
  31. if exists("g:no_plugin_maps") || exists("g:no_gitrebase_maps")
  32. finish
  33. endif
  34. nnoremap <buffer> <silent> <C-A> :<C-U><C-R>=v:count1<CR>Cycle<CR>
  35. nnoremap <buffer> <silent> <C-X> :<C-U><C-R>=v:count1<CR>Cycle!<CR>
  36. let b:undo_ftplugin = b:undo_ftplugin . "|exe 'nunmap <buffer> <C-A>'|exe 'nunmap <buffer> <C-X>'"