Vim Auto-complete plug-in----youcompleteme installation and configuration
Using Vim to write a program without the use of auto-completion plug-ins, there is no similar to the Linux vs visual Assist X such a quick and easy to complete plug-ins? Used to be neocomplcache+code_complete+omnicppcomplete, but the effect is not very good. See a YCM after the plug-in front can say goodbye.
Youcompleteme: An all-in-one, high-speed, full-complement plugin that supports fuzzy search. YCM was developed by Strahinja Val Markovic, a software engineer for Google's search project team, YCM back-end calls Libclang (to get the AST, and of course the semantic Analysis library for other languages), the frontend is developed by C + + (to improve completion efficiency), the outer layer is managed by the PY Thon Package (to become a vim plugin), it's probably the most complex vim plugin I've ever seen installed.
Let's see a full complement.
You can also complete the path auto-completion
Recorded a dynamic giif complement using YCM and ultisnips, which is cool to write code with.
The configuration of my vim can be seen here
Youcompleteme requires VIM version 7.3.584+, which is described in the previous Vim7.4 method of compiling and installing. At the same time Youcompleteme requires the clang version to be more than 3.3. If you want to get the latest clang, you can use SVN to compile the installation according to the method described on the official web site. We are here to introduce the source code compiled installation clang3.3.
- Vim Auto-complete plug-in----youcompleteme installation and configuration
- Compiling and installing iivm-clang3.3
- Installing the Clang standard library
- Installation Configuration Youcompleteme
Compiling and installing llvm-clang3.3
First download the following 4 source code: llvm-3.3 Source code clang-3.3 source code clang-tools-extra-3.3 source code compiler-rt-3.3 source code to establish a directory:
mkdir ~ / llvm-clang
Unzip the 4 files downloaded above to the above 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 corresponding directory of 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 to the ~ / llvm-clang directory and create a new directory llvm-build specifically for compiling llvm-clang, so that it does not pollute the source code.
mkdir llvm-build
cd llvm-build /
../llvm-3.3.src/configure --enable-optimized
Building a compilation environment
After this kind of configuration, llv-clang is installed by default in the directory / usr / local /. If you want to change the installation directory, add the configuration: --prefix = Path to make the input make -j4
(My machine is dual-core) Start compiling
sudo make install
To install
If you want to uninstall, enter in the directory
sudo make uninstall
After installation, enter clang -v to view the version information:
clang -v
Install clang standard library
The standard library of clang-libc ++ (interface layer) and libc ++ abi (implementation layer) need to install header files and dynamic link library (* .so).
Install libc ++
cd ~ / llvm-clang
svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
cd libcxx / lib
./buildit
The header file has been generated to ~ / llvm-clang / libcxx / include /, for clang to find it must be copied to / usr / include / c ++ / v1 /
sudo cp -r ~ / llvm-clang / libcxx / include / / usr / include / c ++ / v1 /
* .so file has been generated ~ / llvm-clang / libcxx / lib / libc ++. so.1.0, for clang access must be copied to / usr / lib /, and create soft link
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
sudo cp ~ / dllvm-clang / libcxx / lib / libc ++. so * / usr / lib /
Similarly, the source code installs libc ++ abi header files and dynamic link libraries:
cd ~ / llvm-clang /
svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi
cd libcxxabi / lib
./buildit
The header file has been generated to ~ / llvm-clang / libcxxabi / include /, for clang to find it must be copied to / usr / include / c ++ / v1 /
sudo cp -r ~ / llvm-clang / libcxxabi / include / / usr / include / c ++ / v1 /
* .so file has been generated ~ / llvm-clang / libcxx / lib / libc ++ abi.so.1.0, for clang access it must be copied to / usr / lib / and create 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
sudo cp ~ / llvm-clang / libcxxabi / lib / libc ++ abi.so * / usr / lib /
The following options can be used to compile the code (not processed for the time being, so the following is not executed):
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 / using clang;
-Werror: treat all compilation warnings as compilation errors;
-Weverything: Turn on all compilation warning options. In GCC, you cannot open all compilation warnings with a single option. You must specify -Wall, -Wextra, and a large number of other scattered options at the same time. For this reason, -Weverything is added to clang. Of course, some warnings are of little significance and can be completely ignored, as follows;
-Wno-disabled-macro-expansion: Macro expressions are prohibited, ignore this warning;
-Wno-float-equal: floating point types should not use! = And == operators, ignore this warning;
-Wno-c ++ 98-compat, -Wno-c ++ 98-compat-pedantic: Codes with new features of C ++ 11 are not compatible with C ++ 98, ignore this warning;
-Wno-global-constructors: there is code executed before main (), ignore this warning;
-Wno-exit-time-destructors: there is executed code after main (), ignore this warning;
-Wno-missing-prototypes: Although there is a function definition but the function prototype is missing, ignore this warning;
-Wno-padded: The structure size should be an integer multiple of 4 bytes, ignore this warning (the compiler automatically adjusts the alignment boundary);
-lc ++: Specify link to /usr/lib/libc++.so standard library;
-lc ++ abi: Specify link to /usr/lib/libc++abi.so standard library. Note: These two options are very important, and the missing will cause the link to fail!
These parameters are set in the YouCompleteMe configuration file. The flags of ycm_extra_conf.py
Install and configure YouCompleteMe
Download the source code. Use vundle to get it, add it in ~ / .vimrc file
Bundle ‘Valloric / YouCompleteMe’
Excuting an order:
$ 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 / third_party / ycmd / cpp
Note: CLANG_INSTALL_PATH here should be replaced with the directory where your own libclang.so is located, for example, mine is / ycm_temp / llvmsrc / build / Release + Asserts / lib (ie: generated by compiling llvm-clang in the above step) If it is, there is also libclang.so under / usr / local / lib /, this directory is also ok. Can be viewed via sudo find / -name "libclang.so" -print
Generate libclang.so and ycm_core.so files in YouCompleteMe. Execute make ycm_core, which will automatically generate two files (libclang.so and ycm_core.so) in ~ / .vim / bundle / YouCompleteMe / python /
make ycm_core
This is not enough, you must also execute the command: make ycm_support_libs. This command will generate the third file ycm_client_support.so. Because YouCompleteMe is based on C / S architecture, there is a saying of server and server.
make ycm_support_libs
Finally set the .ycm_extra_conf.py file.
Unlike many vim plugins, YCM needs to be compiled first, and configuration is also required. After vim starts, YCM will find the current path and the upper path. Ycm_extra_conf.py. In ~ / .vim / bundle / YouCompleteMe / cpp / ycm / The default template is provided in .ycm_extra_conf.py. You can also refer to mine (just change it on the template). However, this solves the problem that the standard library does not find it.
C
C ++
Generally speaking, put a default template in the ~ directory, and then copy another one in the current directory according to different projects.
Add configuration in .vimrc:
"Auto-complete configuration
set completeopt = longest, menu "Make Vim's completion menu behave the same as general IDE (see VimTip1228)
autocmd InsertLeave * if pumvisible () == 0 | pclose | endif "Automatically close the preview window after leaving insert mode
inoremap <expr> <CR> pumvisible ()? "\ <C-y>": "\ <CR>" "Press Enter to select the current item
"The behavior of the up, down, left and right buttons will display other information
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 conflicts with automatic completion
"let g: ycm_key_list_select_completion = [‘ <c-n> ‘]
let g: ycm_key_list_select_completion = [‘<Down>‘]
"let g: ycm_key_list_previous_completion = [‘ <c-p> ‘]
let g: ycm_key_list_previous_completion = [‘<Up>‘]
let g: ycm_confirm_extra_conf = 0 "Close loading. ycm_extra_conf.py prompt
let g: ycm_collect_identifiers_from_tags_files = 1 "Turn on YCM based tag engine
let g: ycm_min_num_of_chars_for_completion = 2 "list the matches from the second typed character
let g: ycm_cache_omnifunc = 0 "Disable caching matches, regenerate matches every time
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 locationlist
inoremap <leader> <leader> <C-x> <C-o>
"Complete in comment input
let g: ycm_complete_in_comments = 1
"Complete in string input
let g: ycm_complete_in_strings = 1
"Comments and text in strings will also be completed
let g: ycm_collect_identifiers_from_comments_and_strings = 0
nnoremap <leader> jd: YcmCompleter GoToDefinitionElseDeclaration <CR> "Jump to definition
This article is reproduced from: http://www.cnblogs.com/zhongcq/p/3630047.html
Reference article: http://www.junevimer.com/2013/12/11/youcompleteme.html
Vim automatic completion plugin-YouCompleteMe installation and configuration