"Turn" vim auto-complete plug-in----youcompleteme installation and configuration

Source: Internet
Author: User



Original URL: http://www.cnblogs.com/zhongcq/p/3630047.html



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 each of the 4 downloaded files to the above list



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 the 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 dedicated to compiling Llvm-clang, so that no source code.



mkdir llvm-build



cd llvm-build/



../llvm-3.3.src/configure --enable-optimized



Building a compilation environment



After this configuration, Llv-clang is installed by default to the directory/usr/local/, if you want to change the installation directory, add the configuration:--prefix=path to make the inputmake -j4



(My machine is dual core) start compiling



sudo make install



To install



If you want to uninstall, enter it in this directory



sudo make uninstall



Once installed, enterclang -vview version information:


Installing the Clang standard library


Clang's standard library ———— libc++ (interface layer) and Libc++abi (Implementation layer) require installation of header files and dynamic-link libraries (*.so).


    • Installing 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~/llvm-clang/libcxx/include/, to let Clang find must be copied to/usr/include/c++/v1/



cp -r ~/llvm-clang/libcxx/include/ /usr/include/c++/v1/



*.so file has been generated ~/llvm-clang/libcxx/lib/libc++.so.1.0, to make clang access must be copied to/usr/lib/and create a 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
    cp ~/dllvm-clang/libcxx/lib/libc++.so* /usr/lib/
Similarly, the source code installs the Libc++abi header file and the dynamic link library:
 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 let Clang find must be copied to/usr/include/c++/v1/



cp -r ~/llvm-clang/libcxxabi/include/ /usr/include/c++/v1/



*.so file has been generated~/llvm-clang/libcxx/lib/libc++abi.so.1.0, to make clang access must be copied to/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/



Subsequent code compilation can be done with 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 of c++11 new features;
    • -stdlib=libc++: Specifies the standard library header file/usr/include/c++/v1/that uses clang;
    • -werror: treats all compile warnings as compilation errors;
    • -weverything: Turns on all compilation warning options. In GCC, it is not possible to open all compilation warnings through a single option, and it must be tedious to specify-wall,-wextra, and a large number of other options that are scattered, adding-weverything to this clang. Of course, some warnings have little meaning and are totally negligible, as follows;
    • -wno-disabled-macro-expansion: Suppresses the use of macro expressions, ignoring this warning;
    • -wno-float-equal: Floating-point types should not use the! = and = = operators, ignoring this warning;
    • -wno-c++98-compat,-wno-c++98-compat-pedantic: Code with C++11 new features is incompatible with c++98, ignoring this warning;
    • -wno-global-constructors: There is code executed before main (), ignoring this warning;
    • -wno-exit-time-destructors: There is code executing after main (), ignoring this warning;
    • -wno-missing-prototypes: Although there are function definitions but missing function prototypes, ignore this warning;
    • -wno-padded: The struct size should be 4-byte integer times, ignoring this warning (the compiler automatically adjusts the alignment boundary);
    • -lc++: Specify the link/usr/lib/libc++.so standard library;
    • -lc++abi: Specifies the link/usr/lib/libc++abi.so standard library. Note: These two options are important and missing will cause the link to fail!


These parameters are set in the Youcompleteme configuration file. ycm_extra_conf.py's Flags


Installation Configuration Youcompleteme
  1. Download the source code. Use Vundle to get it done, add in the VIMRC file
    Bundle ‘Valloric/YouCompleteMe‘
  2. Execute 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 
    Note: The clang_install_path here should be replaced by your own libclang.so directory, such as mine is /ycm_temp/llvmsrc/build/release+asserts/lib (i.e.: The compilation of the above steps Llvm-clang generated), if installed under/usr/local/lib/also have libclang.so, this directory can also. Can be viewed via sudo find/-name "libclang.so"-print
  3. Generate libclang.so and ycm_core.so files in Youcompleteme
    Executemake ycm_core, this will automatically generate two files (libclang.so and ycm_core.so) in the ~/.vim/bundle/youcompleteme/python/directory
  4. This is not enough, and you must also execute the command:make ycm_support_libs. This command only generates a third file, ycm_client_support.so. Because, Youcompleteme is the C/s architecture, so there is the server and service side of the argument.
  5. Final settings.ycm_extra_conf.pyfile.
  6. To add a configuration in. VIMRC:
    "Autocomplete Configuration
    set completeopt = longest, menu "Make Vim's completion menu behave the same as the general IDE (refer to VimTip1228)
    autocmd InsertLeave * if pumvisible () == 0 | pclose | endif "Close the preview window automatically after leaving insert mode
    inoremap <expr> <CR> pumvisible ()? "\ <C-y>": "\ <CR>" "Enter to select the current item
    "The behavior of the up, down, left, and right keys displays additional 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 and autocompletion conflict
    "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
    
    let g: ycm_collect_identifiers_from_tags_files = 1 "Enable YCM tag-based engine
    let g: ycm_min_num_of_chars_for_completion = 2 "List matches starting at the second character typed
    let g: ycm_cache_omnifunc = 0 "Disable caching of matches and regenerate them 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
    "Text in comments and strings is also completed
    let g: ycm_collect_identifiers_from_comments_and_strings = 0
    
    nnoremap <leader> jd: YcmCompleter GoToDefinitionElseDeclaration <CR> "jump to the definition 


"Go" vim auto-complete plug-in----youcompleteme installation and configuration


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.