Use Vim to write c ++CodeBasically, there are not many completion plug-ins to choose from. I use omnicppcomplete. This plug-in relies on tags for completion, and the effect is unsatisfactory.
Clang complete was found some time ago, and the effect was very good (advertisement: d ). so we recommend that you. clang complete is an additional function provided by llvm/clang. clang complete relies on compiling C ++ files. It should obtain the abstract syntax tree for further completion. therefore, the completion effect is very good and accurate. however, it may be slow.
OK. If you are interested, Google llvm/clang and follow the llvm/clang projects. By the way, follow clang_complete. These projects are updated quickly.
Clang complete has two types of completion: one is to use clang (EXEC) to compile the code for completion, the other is to use libclang, and the other is dependent on python. Let's take a look at the other one.
1. Compile Vim to support Python-written plug-ins.
In Debian 6, python2.6-Dev was not installed at first, and the compiled Vim does not support py ...... therefore, first check whether python2.6-Dev is installed. the latest Vim 7.3 supports Python 3, so if you want to support Python 3, check whether the dev package of Python 3 has been installed.
./Configure -- enable-pythoninterp -- enable-Gui = No -- enable-csures -- enable-multibyte -- enable-fontset -- With-features = hugemake-J2
Run make install under the root permission, open vim, input: py, and check the error information to see if python is supported. If not, you can only compile the Code with clang.
2. Install the clang complete plug-in. (giant easy)
To begin ~~, Then follow readme to copy it ~ /. Vim/plugin.
At this time, open a CPP file to see if it can pass ::,., -> to get smart prompts. by the way, clang complete cannot coexist with omnicppcomplete. You must delete omnicppcomplete to work .... in general, as long as you copy the correct location and open all the plug-ins in vimrc, You Can Get Smart prompts.
3.Pre-compile some header files
Clang/libclang are compiled in real time, so the efficiency may be faulty, especially when there are a lot of code. here, the author provides a solution, that is, pre-compilation. the solution is also simple. Create a header file, include your files, and call clang to pre-compile:
Clang-x C ++-header./pchheader. H-fno-exceptions-FNU-runtime-o./pchheader. PCH
The above is the example in README, precompile this pchheader. h, and then
Echo '-include-PCH pchheader. PCH-fgnu-runtime'>. clang_complete
You can.
4.User Option
The pre-compilation mentioned above cannot coexist with libclang, so we do not recommend that you use libclang for compiling. You need to configure it in. vimrc:
Let G: clang_complete_copen =1Let G: clang_periodic_quickfix=1Let G: clang_snippets=1Let G: clang_close_preview=1Let G: clang_use_library= 1Let G: clang_user_options='-Stdlib = libc ++-STD = C ++ 11-imo-depath'
This is my configuration. For more information, see.Clang_user_optionsHere I have enabled C ++ 11 and use libc ++ instead of libstdc ++.
In addition, this. clang_complete can also be used to include the path of the extra header file required by your project. If some header files used in the Code are not found, he will go back to this page to find them. but fortunately, there is no such problem in my Debian.
The following is an image of clang complete completion:
PS:
I added pre-compiled STL On Debian, prompting super fast ~~.Libclang is used to complete all the tasks. The speed is good.
In addition, if you want to use clang complete, your code must be compiled in the past, otherwise there is no way to prompt .... our code is very tragic and used for a lot of GCC extensions, and the writing is not standard ......
Clang 2.8 can better support C ++ 03 and C ++ 0x. It is estimated that 2.9 will improve.
Clang 3.1 currently supports the most C ++ 11