Closed jsatk closed 6 years ago
That's because you mapped <Tab>
to <C-R>=completor#do('complete')<CR>
when the popup menu is not open.
So a better way to reserve the default action of <Tab>
is to use another mapping for triggering completion:
inoremap <expr> <c-n> pumvisible() ? "<C-N>" : "<C-R>=completor#do('complete')<CR>"
Firstly, thanks for your response.
@maralla I ended up modifying a script I was previously using that I stole somewhere online (don't recall).
This does exactly what I want and behaves the same way that many other editors do now with auto completion.
" 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 ) =~ '^\w'
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. Default suggests completions as you type.
let g:completor_auto_trigger = 0
inoremap <expr> <Tab> Tab_Or_Complete()
@maralla what do you think of adding the above to the README? Seems more intuitive behavior.
See gif. When I enter insert mode on a new blank line at column 0 it won't let me tab. I have the
Here's what my completor section looks like in my vimrc.