Skip to content

Instantly share code, notes, and snippets.

@inside
Created December 5, 2012 15:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inside/4216245 to your computer and use it in GitHub Desktop.
Save inside/4216245 to your computer and use it in GitHub Desktop.
Vim tab map for completion
" This can conflict with the default mappings provided by snipmate.
" See the after directory in .vim/bundle/snipMate/after
function! SuperCleverTab()
if strpart(getline('.'), 0, col('.') - 1) =~ '^\s*$'
return "\<Tab>"
elseif pumvisible()
return "\<c-n>"
else
if &omnifunc != ''
return "\<C-X>\<C-O>"
elseif &dictionary != ''
return "\<C-K>"
else
return "\<C-N>"
endif
endif
endfunction
" <C-R> explained:
" You can insert the result of a Vim expression in insert mode using the <C-R>=
" command. For example, the following command creates an insert mode map command
" that inserts the current directory:
" :inoremap <F2> <C-R>=expand('%:p:h')<CR>
inoremap <Tab> <C-R>=SuperCleverTab()<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment