"Go" Ubuntu13.04 configuration: Vim+syntastic+vundle+youcompleteme

Source: Internet
Author: User



Original URL: http://www.cnblogs.com/csuftzzk/p/3435710.html


Preface


I've been using Ubuntu and vim for a while, and I've always had a crazy attitude about the plug-in application under VIM. This time, again on the internet loitering, found a personal blog mentioned the VIM code complement this matter, and mentioned youcompleteme this plugin. Suddenly aroused my desire to toss. I used to use ctags+<c-n> or <C-p> to complete the completion, but its hit rate is relatively low, and sometimes the random match. So decided to youcompleteme this plug-in installation of the application, at the same time, with vundle or let me the. Vim folder to clean up the files.


First, prepare


(1) RELATED LINKS


    1. PPA for Vim 7.4. The Youcompleteme plug-in requires VIM version 7.3.584 and above, while the Ubuntu13.04 source of vim is already relatively old. Therefore, we can add the PPA in the source, or compile the source code to manually update the VIM version.
    2. Vundle. This is a new generation of Vim plugin manager that uses git to install and update plugins. There used to be a pathogen. The benefits of the plug-in Manager are: Use simple, automated management of Vim's plugins. Keep your. Vim folder away from the mess, and from there. VIMRC the world.
    3. CLANG+LLVM. Llvm+clang is a project funded by Apple, and Youcompleteme's precise complement function relies entirely on Clang code parsing. We need to install clang 3.2+ to provide support for YCM.
    4. SVN and Git. Used to check out source code from the code base. In Ubuntu, the installation of both software is very simple, using the Apt-get command can be completed.
    5. Youcompleteme and syntastic. Both plugins are used together. YCM do not say, syntastic for the source of real-time inspection. As with eclipse, syntax errors can be reported in real time during code writing.
    6. Cmake. The following will be used during the compilation process, installation command: sudo apt-get install Cmake.


(2) Configure Vim


  1. Upgrade to 7.3.584+. You need to manually add the PPA (Personal package Archives) under Ubuntu, and you can add them using the command line add-apt-repository, such as:

$ sudo add-apt-repository ppa: nmi / vim-snapshots
$ sudo apt-get update
$ sudo apt-get install vim
Some PPAs also provide source addresses, so you can directly open /etc/apt/source.list to add. The essence of the two is the same. If you compile vim from source, you can refer here.

Download Vundle. Vundle is hosted on Github and requires git to check out the source code.
$ git clone https://github.com/gmarik/vundle.git ~ / .vim / bundle / vundle
The above command directly checks out the source code to the ~ / .vim / bundle / vundle directory.

After downloading the vundle, you need to configure the .vimrc file. The template to be configured is as follows (extracted from github):
set nocompatible "be iMproved
filetype off "required!

set rtp + = ~ / .vim / bundle / vundle /
call vundle # rc ()

"let Vundle manage Vundle
"required!
Bundle ‘gmarik / vundle’

"My bundles here:
"
"original repos on GitHub
Bundle ‘tpope / vim-fugitive’
Bundle ‘Lokaltog / vim-easymotion’
Bundle ‘rstacruz / sparkup’, {‘rtp‘: ‘vim /‘}
Bundle ‘tpope / vim-rails.git’
"vim-scripts repos
Bundle ‘L9’
Bundle ‘FuzzyFinder’
"non-GitHub repos
Bundle ‘git: //git.wincent.com/command-t.git’
"Git repos on your local machine (i.e. when working on your own plugin)
Bundle ‘file: /// Users / gmarik / path / to / plugin’
"...

filetype plugin indent on "required!
It should be noted that the filetype off is not actually needed. Because this command will cause the syntax coloring to fail. This is not configured in my .vimrc. When the required vim plugin is hosted on Github, the plugin can be written as "Bundle 'scrooloose / syntastic'"; when the plugin is on www.vim.org, we only need to write the name of the plugin, plus .vim extension. Otherwise, the vundle cannot update the plugin. Basically, these two situations can meet the needs of most of us.

Use of vundle. First remove all the previously installed plug-ins under ~ / .vim / from "rm -rf". The vundle will take over the management. Open a vim window and execute the command: BundleInstall. Next, vundle will automatically go online to download and install the relevant plug-ins. In this process, vundle will also: helptags command. Therefore, we can view the help documentation of the plugin directly in vim. To delete a plug-in is also very simple, first remove the plug-in entry in ~ / .vimrc, and then enter the vim command: BundleClean. Hey, vundle will automatically clear the plugin folder! Crazy to blast the sky!

Compile the source code of LLVM + Clang. On http://clang.llvm.org, Clang 3.3 does not have Ubuntu13.04 32bit pre-compiled binary program, so I had to download the source code and compile it manually. The command is as follows:
// Checkout LLVM:
cd llvmsrc
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
// Checkout Clang:
cd llvmsrc
cd llvm / tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
// Checkout Compiler-RT:
cd llvmsrc
cd llvm / projects
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
// Get the Test Suite Source Code [Optional]
cd llvmsrc
cd llvm / projects
svn co http://llvm.org/svn/llvm-project/test-suite/trunk test-suite
// Configure and build LLVM and Clang:
cd llvmsrc
mkdir build (for building without polluting the source dir)
cd build
../llvm/configure --enable-optimized
The only thing to note in the above steps is that when configuring, you need to specify the --enable-optimized parameter. Otherwise, the default configure will be the Debug version, a lot of problems. Finally, we use the make command to compile. The compilation process is relatively long and takes about half an hour. This step is mainly to prepare for compiling the YouCompleteMe plugin below.

Second, the configuration
(1) Compile YouCompleteMe. That's right, this plugin needs to be compiled! There are detailed installation and usage methods in the Github project description. However, the Full Installation in the official description does not have the compilation instructions for Ubuntu13.04 32bit, and the instructions use pre-compiled Clang packages. It was executed once according to this instruction, but there was always an error on libclang.so, either the wrong version or the libclang.so was not generated at all. Finally found a post on the Internet, and then combined with the official description of the successful compilation. The compilation steps are as follows:

Download the source code. We have already downloaded the vundle before, so this step is skipped.
Excuting an order:
$ cd ~
$ mkdir ~ / ycm_build
$ cd ~ / ycm_build
$ cmake -G "Unix Makefiles" ~ / .vim / bundle / YouCompleteMe / cpp -DEXTERNAL_LIBCLANG_PATH = ~ / ycm_temp / llvmsrc / lib / libclang.so
$ make ycm_core
It should be noted here that -DEXTERNAL_LIBCLANG_PATH is used to specify the location of libclang.so. If it is not specified, YCM will not work properly, and always report errors like The YCM shut down, crash report ... This libclang.so is generated when we compile Clang. Therefore, the relevant path (that is, ~ / ycm_temp / llvmsrc / lib / libclang.so) needs to be replaced with its own path.

About make. In the official documentation, only used: make ycm_support_libs. But I have repeatedly failed in actual operation. In fact, we must first execute: make ycm_core. This will automatically generate two files (libclang.so and ycm_core.so) in the ~ / .vim / bundle / YouCompleteMe / python / directory, such as:

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, so there is the concept of server and server. In addition, you can also see the service and request logs in the / tmp / ycm_temp / directory, which can even verify this.
Finally, in order to successfully complete the configuration work, we also need to configure the .ycm_extra_conf.py file. There is a configuration template in the project description, what we need to change is the flags part. Use the -isystem flag to add a system header file for analysis, and the -I flag is used to add a third-point header file for analysis. My flags are added at the end as follows:
‘-Isystem’,
‘/ Usr / include’,
‘-Isystem’,
‘/ Usr / include / c ++ /’,
‘-Isystem’,
‘/ Usr / include / i386-linux-gnu / c ++’
In addition, in order to better improve the completion efficiency, we can retain the original tags file generated with Ctags and add it to ~ / .vimrc: let g: ycm_collect_identifiers_from_tag_files = 1. Among them, use: echo tagfiles ( ) You can view the currently used tags file. As for the method of generating tags file, you can see the help file of Ctags or search online.

At this point, the configuration is not over. The .ycm_extra_conf.py file can be for the project, or it can be set globally. For the project, just put it in the root directory of the project. However, each time you open the file, you will be asked whether to load it. At this time, you can set it in ~ / .vimrc: let g: ycm_confirm_extra_conf = 0 to close the prompt. If it is global, it can be set in ~ / .vim / bundle / YouCompleteMe / cpp / ycm / .ycm_extra_conf.py. If there is no problem, you should be able to see the powerful side of YouCompleteMe, the effect is below.
(2) The installation of Syntastic and Vundle is very simple, mainly because of the configuration, so you don't spend time explaining the installation, just look at the configuration. The key and difficult point is the compilation of YouCompleteMe and Clang. These two compilation steps are relatively complicated and the compilation takes a long time. So it took a lot of time to explain.

3. Appendix
(1). This is a picture of C ++ completion. The red cross in the picture is the effect of Syntastic. If you need to complete C, you have to modify it in .ycm_extra_conf.py.

Unexpectedly, YCM can also complete files and directories. . .

The following is Syntastic. The warning and error flags can be configured. When the cursor is on the wrong line, the vim command line will have relevant error messages:

(2) Problems encountered.

The version of libclang.so must be 3.2+, otherwise YCM will not work properly. The above three .so files must be generated by the above make ycm_core and make ycm_support_libs, and cannot be copied manually.
If there is an error that the bits / c ++ config.h file cannot be found, then you can consider copying all files in the folder where the c ++ config.h file exists in the system to /usr/include/c++/4.8 In the / bits directory, refer to the link!
(3) Relevant instructions.

When compiling the vim source code, you need to open the python option.
Plug-in entries in vundle, if hosted on www.vim.org, need to add .vim extension.
A more complete .vimrc template.
Part of my plugin configuration:
"" "" "" "" "Settings of taglist" "" "" "" "" "" "" "" "
"increase the width of the taglist window
let Tlist_WinWidth = 10
"automatically open the taglist window
let Tlist_Auto_Open = 0
"exit wim when only the taglist window exist
let Tlist_Exit_OnlyWindow = 1
"open tags with single click
let Tlist_Use_SingleClick = 1
"close tag folds for inactive buffers
let Tlist_File_Fold_Auto_Close = 1
"show the fold indicator column in the taglist window
let Tlist_Enable_Fold_Column = 1
"Automatically update the taglist to include newly edited files
let Tlist_Auto_Update = 1
"" "" "" "" "" NERDtree settings "" "" "" "" "" "" "" ""
let NERDTreeWinPos = ‘right’
"" "" "" "" "" "mini buffer navigator" "" "" "" "" "" ""
let g: miniBUfExplMapWindowNavVim = 1
let g: miniBufExplMapWindowNavArrows = 1
let g: miniBufExplMapCTabSwitchBufs = 1
let g: miniBufExplModSelTarget = 1
let g: miniBufExplUseSingleClick = 1

"" "" "" "" "" "" "ctags settings" "" "" "" "" "" "" "" "" "" "
set tags + = ~ / .vim / cpptags
set tags + = ~ / .vim / systags

"" "" "" "" "" "color scheme" "" "" "" "" "" "" "" "" "" "" "
let g: molokai_original = 1

"" "" "" "" "" "" "vundle" "" "" "" "" "" "" "" "" "" "" "" "" ""
set nocompatible

set rtp + = ~ / .vim / bundle / vundle /
call vundle # rc ()
   
"let Vundle manage Vundle
"required!
Bundle ‘gmarik / vundle’

"" "" "" "" vim scripts "" "" "" "" "" "" "" "" "" ""
Bundle ‘taglist.vim’
Bundle ‘c.vim’
Bundle ‘minibufexpl.vim’
Bundle ‘grep.vim’
Bundle ‘mru.vim’
Bundle ‘comments.vim’

"" "" "" "" git repo "" "" "" "" "" "" "" "" "
Bundle ‘scrooloose / nerdtree’
Bundle ‘Valloric / YouCompleteMe’
Bundle ‘vim-scripts / AutoClose’
Bundle ‘scrooloose / syntastic’
Bundle ‘Lokaltog / vim-powerline’

"" "" "" "" "" syntastic "" "" "" "" "" "" ""
let g: syntastic_check_on_open = 1
let g: syntastic_cpp_include_dirs = [‘/ usr / include /‘]
let g: syntastic_cpp_remove_include_errors = 1
let g: syntastic_cpp_check_header = 1
let g: syntastic_cpp_compiler = ‘clang ++’
let g: syntastic_cpp_compiler_options = ‘-std = c ++ 11 -stdlib = libstdc ++’
"set error or warning signs
let g: syntastic_error_symbol = ‘?’
let g: syntastic_warning_symbol = ‘?’
"whether to show balloons
let g: syntastic_enable_balloons = 1

"" "" "" "" "" "" "YCM" "" "" "" "" "" "" "" "" "" "" "
let g: ycm_global_ycm_extra_conf = ‘~ / .vim / bundle / YouCompleteMe / cpp / ycm / .ycm_extra_conf.py’
let g: ycm_collect_identifiers_from_tags_files = 1
let g: ycm_seed_identifiers_with_syntax = 1
let g: ycm_confirm_extra_conf = 0
Recommended plugins that are easier to use include:
439 "" "" "" "" vim scripts "" "" "" "" "" "" "" "" "" ""
440 Bundle ‘taglist.vim’
441 Bundle ‘c.vim’
442 Bundle ‘minibufexpl.vim’
443 Bundle ‘grep.vim’
444 Bundle ‘mru.vim’
445 Bundle ‘comments.vim’
446
447 "" "" "" "" git repo "" "" "" "" "" "" "" "" "
448 Bundle ‘scrooloose / nerdtree’
449 Bundle ‘Valloric / YouCompleteMe’
450 Bundle ‘vim-scripts / AutoClose’
451 Bundle ‘scrooloose / syntastic’
452 Bundle ‘Lokaltog / vim-powerline’
    Bundle ‘kien / ctrlp.vim’
(4) Reference link:

cold ‘s world
http://stackoverflow.com/questions/18028071/vim-c-ycm-and-syntastic-include-path-problems
http://stackoverflow.com/questions/9201521/g-4-6-issue-no-bits-cconfig-h-file-as-required-by-the-header-cstring
http://www.cplusplus.com/forum/unices/114261/
http://blog.csdn.net/ywh147/article/details/13625905 (higher value)
http://williamherry.com/blog/2012/08/25/master-vim-04-ctrlp/
http://www.bestofvim.com/plugin/ctrl-p/
[Switch] Ubuntu13.04 configuration: Vim + Syntastic + Vundle + YouCompleteMe

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.