0

I have recently moved to vim and was looking into specific auto-completion plugins and tools to use for C/C++ (after YCM did not work for me). I found and installed Clang Completer and it works like a charm.

The problem I have is that when I open a file and type a statement it does not auto complete or even show me a list of possible statements I could use like it should.

Instead I have to press CTRL+N which then shows me the possible options I have for a specific statement (such as an if statement for example).

My question is: how can I make the clang completer auto-show me all the options I have when programming in C/C++ instead of having to press CTRL+N each time.

6
  • 1
    Welcome to Vi and Vim! Let me see if I understand it... You want something that will show you suggestions automatically, without you having to press a key such as Ctrl+N or Tab, correct? YCM usually does that, why did YCM not work for you? There are other plug-ins too, but knowing why YCM wasn't good for you might help us figure out whether one of the others would be more suitable...
    – filbranden
    Dec 16, 2020 at 21:40
  • 1
    Thank you for the welcome, well YCM was one of the plugins which didnt work for me because i kept getting errors, whilst using it as setting it up just took very very long and i just didnt like it because of that, when i found Clang completer it was a much better options due to easy installation, Besides i thought there would be an option in clang to autocomplete without having to click CTRL+N each time?
    – programmer
    Dec 16, 2020 at 21:42
  • 1
    Section 2 of help says: "Completion is started with CTRL-X CTRL-U |i_CTRL-X_CTRL-U|, or automatically depending on the value of |clang_complete-auto|." I don't see that tag but under clang_complete-complete_auto... if g:clang_complete_auto is equal to 1, automatically complete after ->, ., :: Says it's on by default. Maybe you don't have ->, . or ::.
    – B Layer
    Dec 16, 2020 at 22:03
  • 1
    You can add let g:clang_complete_auto = 1 to your vimrc file. That should do it.
    – filbranden
    Dec 16, 2020 at 23:19
  • 1
    Moot point now, it seems, but as I said the docs say the feature is on by default (i.e. the value of the variable is set to 1). If it didn't work until you added something then it must be set to 0 somewhere prior to that.
    – B Layer
    Dec 17, 2020 at 2:09

1 Answer 1

1

Check out the asyncomplete plug-in. It will automatically show the autocomplete popup menu as you start typing.

This plug-in only provides the base for completion and depends on add-ons to implement specific types of completion. So you will also need asyncomplete-clang for C/C++.

(The asyncomplete-clang add-on says "NOT READY FOR GENERAL USE!", so not sure whether it will even be in a usable state.)

One alternative is to use LSP support. LSP is the Language Server Protocol, which allows you to connect to a separate server process that implements the language-specific features in completion. There are a few LSP implementations for C/C++ (clangd, cquery, ccls) that you might want to experiment with. Unfortunately, this gets fairly complex fairly quickly and there are quite a few moving parts here. But the solution is very flexible and it should be easy to extend it to give you great completion in other languages you end up coding in.

1
  • 1
    Thank you very much i appreciate you, i've got it working :)
    – programmer
    Dec 17, 2020 at 0:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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