开发者

vim keyword complete when omni complete returns nothing?

开发者 https://www.devze.com 2022-12-18 06:15 出处:网络
Im trying to use omni compl开发者_如何学Pythonetions and if it returns nothing i want to use normal keyword completion?

Im trying to use omni compl开发者_如何学Pythonetions and if it returns nothing i want to use normal keyword completion?

i thougt %omnifunc != '' should do it...

but what am i missing? Here is my function.

function! CleverTab()
  if pumvisible()
    return "\<C-N>"
  endif
  if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$'
    return "\<Tab>"
  elseif &omnifunc != ''
    return "\<C-X>\<C-O>"
  else
    return "\<C-N>"
  endif
endfunction
inoremap <Tab> <C-R>=CleverTab()<CR>


let g:stop_autocomplete=0

function! CleverTab(type)
    if a:type=='omni'
        if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$'
            let g:stop_autocomplete=1
            return "\<TAB>"
        elseif !pumvisible() && !&omnifunc
            return "\<C-X>\<C-O>\<C-P>"
        endif
    elseif a:type=='keyword' && !pumvisible() && !g:stop_autocomplete
        return "\<C-X>\<C-N>\<C-P>"
    elseif a:type=='next'
        if g:stop_autocomplete
            let g:stop_autocomplete=0
        else
            return "\<C-N>"
        endif
    endif
    return ''
endfunction

inoremap <silent><TAB> <C-R>=CleverTab('omni')<CR><C-R>=CleverTab('keyword')<CR><C-R>=CleverTab('next')<CR>
0

精彩评论

暂无评论...
验证码 换一张
取 消