views:

260

answers:

1

Im trying to use omni completions 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>
+1  A: 
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>
Nikolay Frantsev
however.. normal tab does not work with that solution? :(
jonaz
oh damn, I forget it ;) anyway, you should double check pumvisible for each menu
Nikolay Frantsev
hmm... not getting it to work, if i tab after a space i get a tab, then immediately i get a new autocomplete menu. i tried this as a first if statement: if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$' return "\<Tab>"
jonaz
so, now it should be fine
Nikolay Frantsev
works like a charm!
jonaz
Michael Gundlach