aboutsummaryrefslogtreecommitdiffstats
path: root/ftplugin/gitcommit.vim
blob: 19577d2e62e22a0909c2a146e338f19ef4ce2a26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function! GitSHAComplete(findstart, base)
	if a:findstart
		" locate the start of the word
		let line = getline('.')
		let start = col('.') - 1
		while start > 0 && line[start - 1] =~ '\a'
			let start -= 1
		endwhile
		return start
	endif

	" Match Git SHAs in the current repository
	let matches = []
	let revs = system('git rev-list --all')
	for m in split(revs)
		if m =~ '^' . a:base
			call add(matches, m)
		endif
	endfor

	return matches
endfunction

function! StartGitSHACompletion()
	let old_completefunc = &completefunc

	set completefunc=GitSHAComplete
	return "\<C-x>\<C-u>"

	let &completefunc = old_completefunc
endfunction

function! ASDF()
	return "\<C-p>"
endfunction

" inoremap <expr> <C-x><C-s> StartGitSHACompletion()
" inoremap <C-x><C-s> <C-r>=StartGitSHACompletion()<CR>
inoremap <expr> <C-x><C-s> StartGitSHACompletion()

inoremap <C-v> <C-r>=ASDF()<CR>