0

I would like to have autocompletion active on its own like on sublime text without doing Ctrl+n.

I would like to have this without any none native plugins as the already existing autocompletion in vim fits my needs.

I guess this can be done through .vimrc but I have no idea how to do it.

  • Have you read this question? It is the second google result for "vim native autocompletion" and it sounds like a duplicate to me. – statox Mar 29 '18 at 12:10
  • No this doesn't answer my question, I would like the autocomplete "choices" to appear on there own like on sublime text or most ide or text editor. – user16659 Mar 29 '18 at 12:18
  • Are you using any plugins? Or do you want to use native completions? Maybe checkout deoplete? – klaus Mar 29 '18 at 12:55
2

Okay, this is really a hacky approach and I am not sure this is guaranteed to work all the time. However I managed to get something to work:

augroup MyCompletion
  autocmd!
  autocmd InsertCharPre * if v:char=~'[a-zA-Z_0-9]' | call feedkeys("\<c-n>", 'it')|endif
augroup end

set completeopt+=noinsert,noselect

The reason I call it hacky and experimental is, that we are using feedkeys() to inject a Control-N character into the input queue whenever a character is entered that matches [a-zA-Z0-9_] (adjust to taste).

However this might be unexpected for Vim and might cause all kind of problems later since the input queue buffer has been tempered with by us and that might be unexpected by Vim, so use with care!

And to make sure, the autocompletion won't overwrite what we have currently written, we need to set :set completeopt+=noinsert,noselect (which basically means open the popup menu, but do not select anything yet and do not insert anything yet.

Also please note, this uses a stupid <Ctrl-N> key, which means that the more clever completions (like e.g. path, omni- or user-defined completions) that are available (see :h ins-completion) won't be used.

Your Answer

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