I want to use the auto complete feature from vim (ctrln). How can I activate this feature automatically after I have entered e.g. 3 chars?
Thank You
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityI want to use the auto complete feature from vim (ctrln). How can I activate this feature automatically after I have entered e.g. 3 chars?
Thank You
A reddit user posted this which could be a base to what you are looking for.
The code creates an autocommand triggered after you insert a character. This autocommand calls a function which will feed the v:char
variable used by the autocompletion mechanism and call the autocompletion. You can then use ctrlp as if you ctrln as you'd do if you had triggered the autocompletion by yourself.
The code also remaps enter to accept the current autocompletion suggestion.
" Minimalist-AutoCompletePop-Plugin
set completeopt=menu,menuone,noinsert
inoremap <expr> <CR> pumvisible() ? "\<C-Y>" : "\<CR>"
autocmd InsertCharPre * call AutoComplete()
fun! AutoComplete()
if v:char =~ '\K'
\ && getline('.')[col('.') - 4] !~ '\K'
\ && getline('.')[col('.') - 3] =~ '\K'
\ && getline('.')[col('.') - 2] =~ '\K' " last char
\ && getline('.')[col('.') - 1] !~ '\K'
call feedkeys("\<C-P>", 'n')
end
endfun
(I repeat that the code isn't mine but was made by maxboisvert it is available on his github)
Also as I said in my comment I think that YouCompleteMe provides this features but I wouldn't recommend that to you. This plugin is really heavy and is a lot of trouble to install and to use.