blob: 143f86a251617aabf1d5b7f5caeb472f48e1bb8e [file] [log] [blame]
Bram Moolenaar8c8de832008-06-24 22:58:06 +00001" Vim filetype plugin
2" Language: git rebase --interactive
Bram Moolenaar5c736222010-01-06 20:54:52 +01003" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00004" Last Change: 2022 Jan 05
Bram Moolenaar8c8de832008-06-24 22:58:06 +00005
6" Only do this when not done yet for this buffer
7if (exists("b:did_ftplugin"))
Bram Moolenaar7a329912010-05-21 12:05:36 +02008 finish
Bram Moolenaar8c8de832008-06-24 22:58:06 +00009endif
10
Bram Moolenaar8c8de832008-06-24 22:58:06 +000011let b:did_ftplugin = 1
12
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000013let &l:comments = ':' . (matchstr(getline('$'), '^[#;@!$%^&|:]\S\@!') . '#')[0]
14let &l:commentstring = &l:comments[1] . ' %s'
15setlocal formatoptions-=t
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020016setlocal nomodeline
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000017let b:undo_ftplugin = "setl com< cms< fo< ml<"
Bram Moolenaar8c8de832008-06-24 22:58:06 +000018
Bram Moolenaarc08ee742019-12-05 22:47:25 +010019function! s:choose(word) abort
Bram Moolenaar7a329912010-05-21 12:05:36 +020020 s/^\(\w\+\>\)\=\(\s*\)\ze\x\{4,40\}\>/\=(strlen(submatch(1)) == 1 ? a:word[0] : a:word) . substitute(submatch(2),'^$',' ','')/e
Bram Moolenaar8c8de832008-06-24 22:58:06 +000021endfunction
22
Bram Moolenaarc08ee742019-12-05 22:47:25 +010023function! s:cycle(count) abort
24 let words = ['pick', 'edit', 'fixup', 'squash', 'reword', 'drop']
25 let index = index(map(copy(words), 'v:val[0]'), getline('.')[0])
26 let index = ((index < 0 ? 0 : index) + 10000 * len(words) + a:count) % len(words)
27 call s:choose(words[index])
Bram Moolenaar8c8de832008-06-24 22:58:06 +000028endfunction
29
Bram Moolenaarc08ee742019-12-05 22:47:25 +010030command! -buffer -bar -range Pick :<line1>,<line2>call s:choose('pick')
31command! -buffer -bar -range Squash :<line1>,<line2>call s:choose('squash')
32command! -buffer -bar -range Edit :<line1>,<line2>call s:choose('edit')
33command! -buffer -bar -range Reword :<line1>,<line2>call s:choose('reword')
34command! -buffer -bar -range Fixup :<line1>,<line2>call s:choose('fixup')
35command! -buffer -bar -range Drop :<line1>,<line2>call s:choose('drop')
36command! -buffer -count=1 -bar -bang Cycle call s:cycle(<bang>0 ? -<count> : <count>)
Bram Moolenaar8c8de832008-06-24 22:58:06 +000037
38if exists("g:no_plugin_maps") || exists("g:no_gitrebase_maps")
Bram Moolenaar7a329912010-05-21 12:05:36 +020039 finish
Bram Moolenaar8c8de832008-06-24 22:58:06 +000040endif
41
Bram Moolenaarc08ee742019-12-05 22:47:25 +010042nnoremap <buffer> <silent> <C-A> :<C-U><C-R>=v:count1<CR>Cycle<CR>
43nnoremap <buffer> <silent> <C-X> :<C-U><C-R>=v:count1<CR>Cycle!<CR>
Bram Moolenaar8c8de832008-06-24 22:58:06 +000044
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000045let b:undo_ftplugin = b:undo_ftplugin . "|exe 'nunmap <buffer> <C-A>'|exe 'nunmap <buffer> <C-X>'"