Recently, I have re-installed vim and compiled and deployed it to complete the plug-in ycm. The plug-in's completion effect and the error message automatically prompted when writing C code are still very good. I can't help but write it down, you can also make a memo to yourself.
Quick installation:
First, refer to my. vimrc configuration. After vundle is installed, go to the ycm folder. Vim/bundle/youcompleteme and find the install. Sh script file. In this case, if you need to complete the semantics of the C language, you need to run install. sh script and then manually add the command -- clang-completer to perform automatic installation. At this time, ycm will go to the clang official website to download libclang. so is supported by ycm semantic completion.
Complete installation:
1. If the previous method cannot be used for installation, you can customize the installation. ycm is a compilation plug-in, so manual compilation is required. First, make sure that the lowest version of VIM is 7.3.584 and Python 2 is supported. If not, you must manually compile a copy of vim. (Check whether python2 is supported. You can input ECHO has ('python' in VIM). If output 1 is supported, 0 indicates that you need to re-compile it)
2. download libclang. so, the author of ycm recommends downloading the official pre-compiled libclang. so instead of using the libclang that comes with your system. If you really want to use libclang in your sysytem, you must ensure that the version number is greater than or equal to 3.3. Otherwise, a random error may occur.
3. Compile the ycm_support_libs library. First, make sure that you have installed Python-dev with the python header file, and then create a Temporary Folder ycm_build
cd ~mkdir ycm_buildcd ycm_buildcmake -G "Unix Makefiles" . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp
The makefile generation process is completed using cmake. Note that this process is intended for students who do not need to complete the C semantics. If you need to complete the C semantics, the steps will be slightly troublesome. You need to download the llvm + clang of the binary release version or manually compile llvm and clang, and then ensure that bin, Lib, and inclulde are in the root directory of the folder, such as ycm_temp/llvm_clang, and then run
cmake -G "Unix Makefiles" -DPATH_TO_LLVM_ROOT=~/ycm_temp/llvm_root_dir . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp
Run after makefile is generated
make ycm_support_libs
Ycm_supprot_libs compilation is completed. For those who want to use the system libclang, You need to input-duse_system_libclang = on to replace-dpath_to_llvm_root flag. if your system has a custom libclang, you can also define a custom libclang,-dexternal_libclang_path =/path/to/libclang. so. at the same time, it should be noted that if you use the clang semantic completion support, the make command will also copy libclang to youcompleteme/python to drive the ycm operation.
Usage:
After ycm compilation, you can enjoy the convenience it brings to you. If you need to complete the semantics of the C language, in addition to the steps just compiled, you also need to provide the compiled flag to ycm for real completion. Ycm search. ycm_extra_conf.py to complete the support, you can also manually provide a global. ycm_extra_conf.py path to perform the default processing for ycm (the ycm search path is from the inside to the outside in turn. If the path cannot be found, the default Global Path is used. I choose to place it under the main directory, in this way, you do not need to set a global path because ycm can always find it ).
In addition. ycm_extra_conf.py: for some simple small projects, use the default file. For the default files, I have disabled-werror because it will cause problems for VIM to prompt syntastic with accurate semantics, in addition, I added an additional sentence-isystem,/usr/include/C ++/4.8, because I found that the default ycm_extra_conf file does not seem to find the C ++ header file. For complex projects, we need to borrow our powerful cmake. Cmake has a command to export and compile the flag,-dcmake_export_compile_commands = on. At this time, cmake will export all the current compilation flags to a JSON database-compilation_commands.json, then we need to manually add the location of your database to the compilation_database_folder row in ycm_extra_conf.py. For example, if you are in SRC, ycm_ectra_conf is in your directory, and your JSON is in build, so you need to write floder =. /build. Open Vim at this time and you will find that your project can be completed, in the process of QT development, I maintained the cmake script and used JSON to allow ycm to find the QT header file for completion, which is very convenient.
Summary:It is said that the most powerful pleasure of VIM lies in its free customization. I feel that many things can also be learned from the vim customization process. This will also be the real pleasure that customization brings to me, forcing me to learn, forcing me to try various situations. I believe that there are not a few people who like Vim customization. I hope this article will help you and my like-minded friends will leave your footprints, after all, with your support, I can be more motivated to write.