1" Vim filetype plugin
2" Language:	git rebase --interactive
3" Maintainer:	Tim Pope <[email protected]>
4" Last Change:	2016 Aug 29
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)
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()
26  call s:choose(get({'s':'edit','p':'squash','e':'reword','r':'fixup'},getline('.')[0],'pick'))
27endfunction
28
29command! -buffer -bar Pick   :call s:choose('pick')
30command! -buffer -bar Squash :call s:choose('squash')
31command! -buffer -bar Edit   :call s:choose('edit')
32command! -buffer -bar Reword :call s:choose('reword')
33command! -buffer -bar Fixup  :call s:choose('fixup')
34command! -buffer -bar Cycle  :call s:cycle()
35" The above are more useful when they are mapped; for example:
36"nnoremap <buffer> <silent> S :Cycle<CR>
37
38if exists("g:no_plugin_maps") || exists("g:no_gitrebase_maps")
39  finish
40endif
41
42nnoremap <buffer> <expr> K col('.') < 7 && expand('<Lt>cword>') =~ '\X' && getline('.') =~ '^\w\+\s\+\x\+\>' ? 'wK' : 'K'
43
44let b:undo_ftplugin = b:undo_ftplugin . "|nunmap <buffer> K"
45