diff options
author | Teddy Wing | 2017-04-28 00:45:24 +0200 |
---|---|---|
committer | Teddy Wing | 2017-04-28 00:45:24 +0200 |
commit | e70d92c495001c0af0037b9fadbeec170d2c318f (patch) | |
tree | 46e0ba8d05f7b5b661dce74a22b23d0c71c7f80f | |
parent | 62ca44d3f5ff9d339baf6a12bd46c68dccf94591 (diff) | |
download | vim-gitcha-e70d92c495001c0af0037b9fadbeec170d2c318f.tar.bz2 |
ftplugin/gitcommit.vim: Experiment providing a custom mapping
Experiment with providing a custom mapping for our Git SHA completion
function. We use <C-x><C-s>.
The custom mapping should set our function as the custom `completefunc`,
call the user completion function by programmatically running
`<C-x><C-u>`, and then unset and restore the previous `completefunc`
value.
This allows us to not clobber a user-defined completion function and
also give ourselves a special custom <C-x> mapping.
Just experimenting for now. Figured out how to get this to work using a
test `ASDF` function along with these resources:
* http://stackoverflow.com/questions/15643234/remapping-tab-completions-in-vim
* https://github.com/ervandew/supertab/blob/master/plugin/supertab.vim
* http://stackoverflow.com/questions/6926034/creating-a-mapping-for-insert-mode-but-not-for-autocomplete-submode
It works. The only problem is that we can't restore the old
`completefunc` value. Thinking about ways to do this, and for now my
most promising idea is to use the `CursorMovedI` autocommand.
-rw-r--r-- | ftplugin/gitcommit.vim | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/ftplugin/gitcommit.vim b/ftplugin/gitcommit.vim index daed923..19577d2 100644 --- a/ftplugin/gitcommit.vim +++ b/ftplugin/gitcommit.vim @@ -21,4 +21,21 @@ function! GitSHAComplete(findstart, base) return matches endfunction -set completefunc=GitSHAComplete +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> |