1

In insert mode, when you hit ctrlp on a partially written word, a menu pops up with possible matches for completion.

How can I customize those matches ?

(I have a ruby-clangc gem that I want to use with the ruby-neovim gem in order to write my completion plugin for C/C++ code)

migrated from unix.stackexchange.com Jul 19 '16 at 10:34

This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.

  • 2
    have a look at :h 'completefunc' – nobe4 Jul 19 '16 at 11:00
  • Also look at YouCompleteMe, vim-clang, and clang_complete. Completion for C/C++ works particularly well these days. There's also supertab, if you don't care to remember all those Ctrl-mumble combinations. – Sato Katsura Jul 19 '16 at 13:40
  • I knew them but I wanted to learn how to do it in vimscript. I insist to write my own in ruby (just for me) even if those that already exist work well. Don't ask why I know that it doesn't make sense. I have already my clang completion github.com/cedlemo/ruby-clangc/blob/master/samples/complete.rb in ruby. Just have to use it with the ruby-neovim. – cedlemo Jul 19 '16 at 13:51
  • Then you might want to add this information to your question. Also explain what problem do you have with your completion code. People are likely to misunderstand your point otherwise. – Sato Katsura Jul 19 '16 at 13:55
4

About ctrlp, the doc says:

Find previous match for words that start with the keyword in front of the cursor, looking in places specified with the 'complete' option. The found keyword is inserted in front of the cursor.

You can then look at :h'complete' to learn how to modify the behavior of the completion.

You'll see that you have several options to make the search of the match restricted to the current buffer, using the other loaded buffers or even looking for the spell dictionaries.

To modify the setting simply add a line like this in your .vimrc:

set complete=.,w,b,u

Now for your completion plugin what you are looking for is a custom comlete function. Vims allows you to write such a function, for more information you should refer this question and to the doc:


I think you might also be interested in reading :h ins-completion which explains how the different completion modes of Vim works. (There are about ten different completion modes used to complete different items, learning them can be long but it should make your completion pretty efficient in the end)

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.