Vim: Creating .clang_complete using CMake

The clang_complete plugin for Vim, offers superior code completion. If your project is anything but trivial, it will only do so if you provide .clang_compelete file with the right compilation argument. The easy way to do so is by using the script that comes with it to record the options directly into the .clang_compelete file. Usually one does

make CXX='~/.vim/bin/ clang++'

However, the makefile generated by CMake doesn’t support the CXX configuration.

The solution is to call CMake with the CXX environment variable set:

CXX="$HOME/.vim/bin/ clang++" cmake ..

Note that this will create the clang_complete file in the build directory (I’ve assumed out-of-place build), so just copy over the file to the working dir of your vim so it can find it. You’ll need to re-run cmake again (without the CXX, to disable re-creating the .clang_complete file each time.

While looking for this solution, I’ve first tried solving it by setting the CMAKE_CXX_COMPILER variable in CMake, however for some strange reason it didn’t like it, saying that the compiler wasn’t found (it shuns command line arguments given in the compiler command).

The more I use clang_compelete the more awesome I find it. It has it quirks but nonetheless it’s much simpler and better than manually creating tag files for each library.

Updated 6/1/2014: When setting CXX use $HOME instead of ~ (fix issues with newer versions of CMake).

7 thoughts on “Vim: Creating .clang_complete using CMake

  1. Hello,

    Using Ubuntu, I can run the command you propose (CXX=”$HOME/.vim/bin/ clang++” cmake ..) from my “build/CMakeFiles” directory, and CMake seems to run as usual. But no .clang_complete is generated in “build/CMakeFiles” or in “build”. Am I missing something?

  2. Sorry, my message was not clear. I cannot find the .clang_complete file at all after running both commands. But I don’t get any error message… Actually, it seems that CMake ignores the CXX.

  3. Did you make clean beforehand? You can also pass VERBOSE=1 to make to see detailed output of commands being executed. The .clang_complete file should be created in your build directory.

  4. I have the same problem as James, I was originaly compiling with ninja and it didn’t work. So I switched to make, erased my build re run cmake with the CXX argument and still nothing.

    And when I create the .clang_complete file myself the autocomplete is still messed up…
    Shame really.

  5. Here is what worked for me
    sudo chmod a+x $HOME/.vim/bin/
    CXX=”$HOME/.vim/bin/ g++” sudo cmake ..
    sudo make

    and then ls -a shows my .clang_complete file but still emtyp though.

  6. Hi, when I
    CXX=”$HOME/.vim/bin/ clang++” cmake ..
    I returns is not able to compile a simple test program.
    and something like permission denied.

    I would appreciate if you can help me

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.