If you use Vim to write programs, you must use the automatic completion plug-in. Is there a convenient and quick completion plug-in similar to Visual Assist X in VS in Linux? Previously, we used neocomplcache + code_complete + omnicppcomplete, but the effect is still not very good. After YCM is available, you can say goodbye to the plug-in.
YouCompleteMe: a key-based plug-in that supports fuzzy search and high-speed completion. YCM is developed by Strahinja Val Markovic, a software engineer in the google search project team. The YCM backend calls libclang (to obtain AST, and of course there are semantic analysis libraries in other languages) the front end is developed by C ++ (to improve the completion rate), and the outer layer is encapsulated by python (to become the vim plug-in). It may be the most complicated vim plug-in I have ever seen.
Recommended reading:
Vim Learning Guide
Quick learn Vi Editor
Powerful Vim Editor
Build a Vim Development Environment on CentOS 6.2
Vim 7.4a released, a new and faster Regular Expression Engine
Install the highlighted Vim editing tool in CentOS 5.4
Vim tips: C language settings
Set the Vim row number in Ubuntu
Vim editor basic tutorial
First look at the completion
You can also perform automatic path completion.
YouCompleteMe requires Vim version 7.3.584 +. The method for compiling and installing Vim7.4 has been described earlier. At the same time, YouCompleteMe requires that the clang version be 3.3 or later. If you want to obtain the latest clang, you can use SVN to compile and install it according to the method described on its official website. Here we will introduce how to compile and install clang3.3.
Directory
- Vim auto-completion plug-in-YouCompleteMe installation and configuration
- Compile and install IIvm-clang3.3
- Install clang standard library
- Install and configure YouCompleteMe
Compile and install llvm-clang3.3
First download the following 4 source code: llvm-3.3 source code clang-3.3 clang-tools-extra-3.3 source code compiler-rt-3.3 source code build directory:
Free in http://linux.bkjia.com/
The username and password are both www.bkjia.com
The specific download directory is in/July 6,/July 8,/Vim Automatic completion Plug-In ---- YouCompleteMe installation and configuration
For the download method, see
mkdir ~/llvm-clang
Decompress the four files downloaded above to the preceding directory.
tar -xvzf llvm-3.3.src.tar.gz
tar -xvzf compiler-rt-3.3.src.tar.gz
tar -xvzf clang-tools-extra-3.3.src.tar.gz
tar -xvzf cfe-3.3.src.tar.gz
Then, move the tool to the directory corresponding to llvm so that clang, clang-tools-extra and compiler-rt can be compiled with llvm:
mv cfe-3.3.src/ llvm-3.3.src/tools/clang/
mv clang-tools-extra-3.3.src/ llvm-3.3.src/tools/clang/extra/
mv compiler-rt-3.3.src/ llvm-3.3.src/projects/compiler-rt/
Download the latest LLVM, clang, and auxiliary Library source code available:
cd ~/llvm-clang svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm cd llvm/tools svn co http://llvm.org/svn/llvm-project/cfe/trunk clang cd ../.. cd llvm/tools/clang/tools svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra cd ../../../.. cd llvm/projects svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt cd ..
Return ~ /Llvm-clang directory, and create a directory named llvm-build to compile llvm-clang so that the source code is not contaminated.
mkdir llvm-build
cd llvm-build/
../llvm-3.3.src/configure --enable-optimized
Build a compilation environment
After this configuration, llv-clang is installed in the/usr/local/directory by default. If you want to change the installation directory, add the configuration: -- prefix = Path to specify the input.make -j4
(My machine is dual-core) start compiling
sudo make install
Install
Enter
sudo make uninstall
After installation, enterclang -v
View version information:
Install clang standard library
The standard library of clang-libc ++ (interface layer) and libc ++ abi (Implementation Layer) requires the installation of header files and dynamic link library (*. so ).
The header file has been generated~/llvm-clang/libcxx/include/
To make clang find the file that must be copied/usr/include/c++/v1/
cp -r ~/llvm-clang/libcxx/include/ /usr/include/c++/v1/
* The. so file has been generated ~ /Llvm-clang/libcxx/lib/libc ++. so.1.0
ln -s ~/llvm-clang/libcxx/lib/libc++.so.1.0 ~/llvm-clang/libcxx/lib/libc++.so.1 ln -s ~/llvm-clang/libcxx/lib/libc++.so.1.0 ~/llvm-clang/libcxx/lib/libc++.so cp ~/dllvm-clang/libcxx/lib/libc++.so* /usr/lib/
Similarly, the header file and dynamic link library of libc ++ abi are installed in the source code:
cd ~/llvm-clang/ svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi cd libcxxabi/lib ./buildit
The header file has been generated~/llvm-clang/libcxxabi/include/
To make clang find the file that must be copied/usr/include/c++/v1/
cp -r ~/llvm-clang/libcxxabi/include/ /usr/include/c++/v1/
* The. so file has been generated.~/llvm-clang/libcxx/lib/libc++abi.so.1.0
To allow clang access, it must be copied/usr/lib/
And create a soft link
ln -s ~/llvm-clang/libcxxabi/lib/libc++abi.so.1.0 ~/llvm-clang/libcxxabi/lib/libc++abi.so.1
ln -s ~/llvm-clang/libcxxabi/lib/libc++abi.so.1.0 ~/llvm-clang/libcxxabi/lib/libc++abi.so
cp ~/llvm-clang/libcxxabi/lib/libc++abi.so* /usr/lib/
You can compile the code using the following options:
clang++ -std=c++11 -stdlib=libc++ -Werror -Weverything -Wno-disabled-macro- expansion -Wno-float-equal -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno- global-constructors -Wno-exit-time-destructors -Wno-missing-prototypes -Wno-padded -lc++ -lc++abi main.cpp
Parameter description:
- -Std = c ++ 11: use the new features of C ++ 11;
- -Stdlib = libc ++: Specify the standard library header file/usr/include/c ++/v1/that uses clang /;
- -Werror: All compilation warnings are considered as compilation errors;
- -Weverything: Enable all compilation warning options. In GCC, you cannot open all compilation warnings using a single option. You must specify-Wall,-Wextra, and a large number of scattered other options at the same time. Therefore, clang adds-Weverything. Of course, some warnings are of little significance and can be ignored completely, as shown below;
- -Wno-disabled-macro-expansion: macro expressions are not allowed. Ignore this warning;
- -Wno-float-equal: The floating point type should not be used! = And = Operator. Ignore this warning;
- -Wno-c ++ 98-compat and-Wno-c ++ 98-compat-pedantic: the new C ++ 11 code generation cannot be compatible with C ++ 98. Ignore this warning;
- -Wno-global-constructors: Code executed before main (). Ignore this warning;
- -Wno-exit-time-destructors: Code executed after main (). Ignore this warning;
- -Wno-missing-prototypes: this warning is ignored if a function is defined but a function prototype is missing;
- -Wno-padded: the struct size should be 4-byte integer multiple. Ignore this warning (the compiler automatically adjusts the alignment boundary );
- -Lc ++: Specifies the link/usr/lib/libc ++. so standard library;
- -Lc ++ abi: Specify the link/usr/lib/libc ++ abi. so standard library. Note: These two options are very important. Missing options will cause Link failure!
These parameters are set in flags of YouCompleteMe configuration file. ycm_extra_conf.py.
Install and configure YouCompleteMe
- Download the source code. Use vundle and add it to the vimrc file.
Bundle 'Valloric/YouCompleteMe'
- Run the following command:
$ cd ~ $ mkdir ~/ycm_build $ cd ~/ycm_build $ cmake -G "Unix Makefiles" -DUSE_SYSTEM_LIBclang=ON -DEXTERNAL_LIBCLANG_PATH=CLANG_INSTALL_PATH/libclang.so . ~/.vim/bundle/YouCompleteMe/cpp
- Generate libclang. so and ycm_core.so files in YouCompleteMe
Runmake ycm_core
In ~ /. Vim/bundle/YouCompleteMe/python/directory automatically generates two files (libclang. so and ycm_core.so)
- This is not enough. You must also execute the command:
make ycm_support_libs
. This command generates the third file ycm_client_support.so. Because YouCompleteMe is in the C/S architecture, there is a saying about servers and servers.
- Final settings
.ycm_extra_conf.py
File.
- Add configuration in. vimrc:
"Automatic completion configuration set completeopt = longest, menu" make Vim's completion menu Behavior consistent with general IDE (refer to VimTip1228) autocmd InsertLeave * if pumvisible () = 0 | pclose | endif "automatically closes the preview window inoremap <expr> <CR> pumvisible ()? "\ <C-y> ": "\ <CR>" "press enter to select the current item" other information is displayed in inoremap <expr> <Down> pumvisible ()? "\ <C-n>": "\ <Down>" inoremap <expr> <Up> pumvisible ()? "\ <C-p>": "\ <Up>" inoremap <expr> <PageDown> pumvisible ()? "\ <PageDown> \ <C-p> \ <C-n>": "\ <PageDown>" inoremap <expr> <PageUp> pumvisible ()? "\ <PageUp> \ <C-p> \ <C-n>": "\ <PageUp>" "youcompleteme default tab s-tab and Automatic completion conflict" let g: ycm_key_list_select_completion = ['<c-n>'] let g: ycm_key_list_select_completion = ['<Down>'] "let g: ycm_key_list_previus_completion = ['<c-p>'] let g: ycm_key_list_previus_completion = ['<Up>'] let g: ycm_confirm_extra_conf = 0 "Disable loading. ycm_extra_conf.py prompt let g: ycm_collect_identifiers_from_tags_files = 1 "enable YCM Based on the label engine let g: labels = 2" starts listing the matching items from 2nd characters. let g: ycm_cache_omnifunc = 0 "indicates that cache matching items are prohibited. Each time, the matching item let g: ycm_seed_identifiers_with_syntax = 1" syntax keyword completion nnoremap <F5>: ycmForceCompileAndDiagnostics <CR> "force recomile with syntastic" nnoremap <leader> lo: lopen <CR> "open locationlist" nnoremap <leader> lc: lclose <CR> "close locationlistinoremap <leader> <C-x> <C-o>" can also complete let g in the comment input: ycm_complete_in_comments = 1 "the string input can also be supplemented with let g: ycm_complete_in_strings = 1" the comment and the text in the string will also be supplemented with let g: character = 0 nnoremap <leader> jd: ycmCompleter GoToDefinitionElseDeclaration <CR> "Jump to definition