1" Vim filetype plugin 2" Language: git rebase --interactive 3" Maintainer: Tim Pope <[email protected]> 4" Last Change: 2019 Dec 05 5 6" Only do this when not done yet for this buffer 7if (exists("b:did_ftplugin")) 8 finish 9endif 10 11runtime! ftplugin/git.vim 12let b:did_ftplugin = 1 13 14setlocal comments=:# commentstring=#\ %s formatoptions-=t 15setlocal nomodeline 16if !exists("b:undo_ftplugin") 17 let b:undo_ftplugin = "" 18endif 19let b:undo_ftplugin = b:undo_ftplugin."|setl com< cms< fo< ml<" 20 21function! s:choose(word) abort 22 s/^\(\w\+\>\)\=\(\s*\)\ze\x\{4,40\}\>/\=(strlen(submatch(1)) == 1 ? a:word[0] : a:word) . substitute(submatch(2),'^$',' ','')/e 23endfunction 24 25function! s:cycle(count) abort 26 let words = ['pick', 'edit', 'fixup', 'squash', 'reword', 'drop'] 27 let index = index(map(copy(words), 'v:val[0]'), getline('.')[0]) 28 let index = ((index < 0 ? 0 : index) + 10000 * len(words) + a:count) % len(words) 29 call s:choose(words[index]) 30endfunction 31 32command! -buffer -bar -range Pick :<line1>,<line2>call s:choose('pick') 33command! -buffer -bar -range Squash :<line1>,<line2>call s:choose('squash') 34command! -buffer -bar -range Edit :<line1>,<line2>call s:choose('edit') 35command! -buffer -bar -range Reword :<line1>,<line2>call s:choose('reword') 36command! -buffer -bar -range Fixup :<line1>,<line2>call s:choose('fixup') 37command! -buffer -bar -range Drop :<line1>,<line2>call s:choose('drop') 38command! -buffer -count=1 -bar -bang Cycle call s:cycle(<bang>0 ? -<count> : <count>) 39 40if exists("g:no_plugin_maps") || exists("g:no_gitrebase_maps") 41 finish 42endif 43 44nnoremap <buffer> <expr> K col('.') < 7 && expand('<Lt>cword>') =~ '\X' && getline('.') =~ '^\w\+\s\+\x\+\>' ? 'wK' : 'K' 45nnoremap <buffer> <silent> <C-A> :<C-U><C-R>=v:count1<CR>Cycle<CR> 46nnoremap <buffer> <silent> <C-X> :<C-U><C-R>=v:count1<CR>Cycle!<CR> 47 48let b:undo_ftplugin = b:undo_ftplugin . "|exe 'nunmap <buffer> K'|exe 'nunmap <buffer> <C-A>'|exe 'nunmap <buffer> <C-X>'" 49