Clang Complete for Vim

25,400

Solution 1

Try opening a sample file

vim /tmp/sample.cpp

and enter some cpp code

#include <iostream>

int main() {
  std:: // <-- this should complete
}

Note that you actually need to include the headers, since completion is done with the compiler. If this works, but your project still keeps saying "Pattern not found" then clang++ is probably not able to compile your project. Do you use any -I switches when you compile your code? Add them to a file named .clang_complete in your project directory.

For me this works fine with my .vim/plugin folder containing only the clang_complete.vim file that is available for download:

$ find .vim
.vim
.vim/plugin
.vim/plugin/clang_complete.vim

... but in this issue report https://github.com/Rip-Rip/clang_complete/issues/39 it is suggested that you might need more than that file (additional files are in the git repo).

Solution 2

I had the same problem and resolved it by adding the following to my .vimrc

let g:clang_user_options='|| exit 0'

Solution 3

The following got things working for me on Cygwin using clang version 3.0 (tags/RELEASE_30/final), as well as on Windows using the Clang build instructions and a version checked out from trunk (usually stable, as I've read) yesterday (clang version 3.1 (trunk 154056)) and built with Visual Studio 2010:

" clang_complete
let g:clang_complete_auto = 0
let g:clang_complete_copen = 1
" :h clang_complete-auto_user_options
if has('win32unix') " Cygwin
       " Using libclang requires a Vim built with +python
       let g:clang_use_library = 1
       " Mit der Option "gcc" kriege ich Fehler.
       " Remove "gcc" option as it causes errors.
       let g:clang_auto_user_options='path, .clang_complete'
elseif has('win32') " Windows
       let g:clang_auto_user_options='path, .clang_complete'
       let g:clang_use_library = 1
       let g:clang_library_path='D:\Sourcen\LLVM\build\bin\Debug'
endif

Note that the Windows version may have sporadic assertion failures but works fine, although not exactly like the Cygwin version. Guess it's to do with using MSVC versus GCC header files.

The Cygwin version has an initial error: release unlocked lock, but it works regardless.

Solution 4

Did you try to compile the code outside Vim, by explicitly invoking Clang on the command-line?

I had the same problem with my code, but it turns out Clang was not able to compile my code due to usage of the MPI libraries (mpich2). Maybe a similar problem is causing Clang to fail in your case? In my case, if I remove the MPI-dependencies, everything works fine, for example in something like:

#include <iostream>
#include <string>

int main() {
    std::string myString("test string");
    std::cout << myString.size() << std::endl; // After typing the dot, I get a list of std::string methods
}

By-the-way, I still miss clang_complete in my MPI code. Did anyone find a solution for this?

Share:
25,400

Related videos on Youtube

dalibocai
Author by

dalibocai

Live a meaningful life.

Updated on July 14, 2020

Comments

  • dalibocai
    dalibocai almost 4 years

    I copied clang_complete.vim to plugin, but when I typed . after some variable, it says:

    pattern not found

    I searched this issue, and somebody said I should configure g:clang_complete_auto: and g:clang_complete_copen:. How can I do this?

  • etaty
    etaty about 13 years
    @dalibocai Can you test with a small project of just one file? Have you got others plugins?
  • dalibocai
    dalibocai about 13 years
    I test it on std::string, and it does not work. I already deleted all omni completion files. I tested clang++, it works well.

Related