2010-01-26 71 views
3

我試圖使用omni完成,如果它沒有返回任何我想使用正常的關鍵字完成?當omni complete vim關鍵字完成時,什麼也不返回?

我thougt%omnifunc!=''應該這樣做...
但我失蹤了什麼? 這是我的功能。

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> 

回答

4
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

但是..正常的標籤不會與解決方案的工作? :( – jonaz 2010-01-26 12:05:31

+0

哦該死的,我忘記了;)無論如何,你應該仔細檢查pumvisible每個菜單 – 2010-01-26 15:40:48

+0

嗯...沒有得到它的工作,如果我選擇後空間我得到一個選項卡,然後立即我得到一個新的自動完成菜單。我試過這個作爲第一條語句: if strpart(getline('。'),0,col('。') - 1)=〜'^ \ s * $' return「\ 」 – jonaz 2010-01-26 16:09:58