问题
I've got a crazy little challenge. I'd like to remap tab and shift + tab to the basic tab completions in vim. Here's where I started:
set completeopt=
inoremap <tab> <C-n>
inoremap <S-tab> <C-p>
That didn't have any effect at all, and I also realized it might be messing up my snippets plugin. I went googling around and found this: http://vim.wikia.com/wiki/Smart_mapping_for_tab_completion, but had little luck implementing any of the suggestions.
I'd like to map to tab and to shift + tab, without losing snippet functionality. Any help would rock!
Update: I also tried this with now luck. It had no perceivable effect.
fu! InsertTabWrapper(direction)
let char_before = col('.') - 1
if !char_before || getline('.')[char_before - 1] !~ '\k'
return "\<tab>"
elseif "backward" == a:direction
return "\<c-p>"
else
return "\<c-n>"
endif
endfu
inoremap <tab> <c-r>=InsertTabWrapper("forward")<cr>
inoremap <s-tab> <c-r>=InsertTabWrapper("backward")<cr>
回答1:
I agree with you that mapping <tab>
is a headache thing in vim.
Personally I have SuperTab, Neocompletecache, Snipmate and pydiction.... it really took some time to let them work together, with <tab>
... even if not (maybe) perfect, it is enough for my daily usage.
Back to your problem, you could consider to install a plugin called superTab
(https://github.com/ervandew/supertab) and in your .vimrc
add these lines:
let g:SuperTabDefaultCompletionType = 'context'
let g:SuperTabContextTextOmniPrecedence = ['&omnifunc','&completefunc']
let g:SuperTabRetainCompletionType=2
inoremap <expr><Enter> pumvisible() ? "\<C-Y>" : "\<Enter>"
inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
then .... good luck... I hope it works for your requirement.
来源:https://stackoverflow.com/questions/15643234/remapping-tab-completions-in-vim