Browse Source

Add completor.vim on TAB

Frans Bergman 5 years ago
parent
commit
8de5b6428f
1 changed files with 28 additions and 0 deletions
  1. 28 0
      .vimrc

+ 28 - 0
.vimrc

@@ -109,4 +109,32 @@ filetype plugin indent on    " required
 " ########## Plugin Settings ########## {{{
 autocmd FileType java setlocal omnifunc=javacomplete#Complete
 call neomake#configure#automake('nrwi', 500)
+
+" Use TAB to complete when typing words, else inserts TABs as usual.  Uses
+" dictionary, source files, and completor to find matching words to complete.
+
+" Note: usual completion is on <C-n> but more trouble to press all the time.
+" Never type the same word twice and maybe learn a new spellings!
+" Use the Linux dictionary when spelling is in doubt.
+function! Tab_Or_Complete() abort
+    " If completor is already open the `tab` cycles through suggested completions.
+    if pumvisible()
+        return "\<C-N>"
+        " If completor is not open and we are in the middle of typing a word then
+        " `tab` opens completor menu.
+    elseif col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^[[:keyword:][:ident:]]'
+        return "\<C-R>=completor#do('complete')\<CR>"
+    else
+        " If we aren't typing a word and we press `tab` simply do the normal `tab`
+        " action.
+        return "\<Tab>"
+    endif
+endfunction
+
+" Use `tab` key to select completions.  Default is arrow keys.
+inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
+inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
+
+" Use tab to trigger auto completion.
+inoremap <expr> <Tab> Tab_Or_Complete()
 " }}}