From 67b9c9d4f0e7328b523d0c1ced6672742eec60c0 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Mon, 4 Oct 2021 21:00:52 -0700 Subject: [PATCH] [vim] use omnicompletion for tab-completion --- .vimrc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.vimrc b/.vimrc index 737cab8..dcf6afb 100644 --- a/.vimrc +++ b/.vimrc @@ -115,15 +115,20 @@ augroup DisableAutoComment autocmd BufEnter * setlocal formatoptions-=o augroup END -" https://vim.fandom.com/wiki/Autocomplete_with_TAB_when_typing_words -function! TabOrComplete() - if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w' - return "\" - else +" :help ins-completion +function! CleverTab() + if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$' return "\" + + " https://vim.fandom.com/wiki/Smart_mapping_for_tab_completion + elseif exists('&omnifunc') && &omnifunc != '' + return "\\" + + else + return "\" endif endfunction -inoremap =TabOrComplete() +inoremap =CleverTab() " }}}