Skip to content

Instantly share code, notes, and snippets.

@bernardeli
Created August 25, 2014 01:04
Show Gist options
  • Save bernardeli/875a3451c6273ae91b09 to your computer and use it in GitHub Desktop.
Save bernardeli/875a3451c6273ae91b09 to your computer and use it in GitHub Desktop.
clever-tab.vim
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment