2

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

2
  • You can use abbreavtions if you want. Please go through other questions. Someone had already created a function for this.
    – SibiCoder
    Jul 22, 2016 at 7:42
  • I think that you'll need a plugin to automatically call the completion (or you'll need to code it by yourself). I think that youcompleteme provides this feature. BUT I really don't encourage you to use it: I can't count the posts I've seen about problems with the installation or the usage of this plugin, in my opinion you'd better get used to the completion mechanism of Vim which is pretty well done. I think that messing your configuration with such a plugin is a loose of time, but if you really want an automatic autocomplete give it a try
    – statox
    Jul 22, 2016 at 8:19

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.