From bc4fcb2b082805914d6e87ff38516dbafc5c5538 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 29 Apr 2017 04:38:49 +0200 Subject: Move ftplugin to ftplugin/gitcommit/gitcha.vim To ensure that we don't conflict with the real "gitcommit" ftplugin, move ours into a new custom file. As described in :h ftplugin-name we can create additional ftplugins for the same filetype by putting our script in a directory named for the filetype. --- ftplugin/gitcommit/gitcha.vim | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 ftplugin/gitcommit/gitcha.vim (limited to 'ftplugin/gitcommit') diff --git a/ftplugin/gitcommit/gitcha.vim b/ftplugin/gitcommit/gitcha.vim new file mode 100644 index 0000000..e08f2e0 --- /dev/null +++ b/ftplugin/gitcommit/gitcha.vim @@ -0,0 +1,34 @@ +let s:old_completefunc = &completefunc + +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 + + " Restore user completion function + let &completefunc = s:old_completefunc + + " 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() + set completefunc=GitSHAComplete + return "\\" +endfunction + +inoremap StartGitSHACompletion() -- cgit v1.2.3