Linux Fundamentals 15: Using Vim to build a C + + development environment on CENTOS7

Source: Internet
Author: User
Tags diff git clone

The previous blog shows how to use Vim to build a C + + development environment on UBUNTU16:

Linux base 12Building a C + + IDE with vim

This blog will show you how to use Vim to build a similar C + + development environment on CENTOS7. The two sets of environment are similar, is the use of vim powerful plug-in extension function, the difference is that the use of Ubuntu plugin Manager is Vim-addon-manager, and CentOS7 on the use of Vbundle as a plug-in manager. The Vbundle feature is the automatic installation and update of plugins, which are typically stored on GitHub.

This blog mainly refers to the following sections of the blog:

Https://www.cnblogs.com/hugb/p/7450845.html

75331822

1. Installing vim8.0

Download vim source code from GitHub.

git clone https://github.com/vim/vim.git

Compile:

./configure--prefix=/opt/test/--with-features=huge-enable-pythoninterp--with-python-config-dir=/usr/lib/ Python2.7/config--enable-cscope

Make all DOC Info

There are some compilation errors that can be ignored here when you compile doc.

Install to the specified directory:

Make install

View version number:

[Email protected] install]$ vim--version
Vim-vi Improved 8.0 (SEP, compiled Apr 14 2018 06:54:13)
Includes patches: 1-1704
[Omit some details here]

2. Create a. vimrc file with the following content:

1Cat.VIMRC2 Setnocompatible3FileTypeoff                 4 5 SetRtp+=~/.vim/bundle/vundle.Vim6 PagerVundle#begin ()7 8Plugin ' Gmarik/vundle.Vim '9Plugin ' bling/Vim-airline 'TenPlugin ' scrooloose/Nerdtree ' OnePlugin ' KIEN/CTRLP.Vim ' APlugin ' TagList.Vim ' -Plugin ' valloric/Youcompleteme ' - Plugin ' Winmanager ' the Plugin ' gdbmgr ' -  - Pagervundle#End() -  +  -FileType plugin Indent on  +  A"Brief Help at":P luginlist-Lists configured plugins -":P lugininstall-installs plugins, append '! ' to update or just:P luginupdate -":P LuginsearchFoo-searches forFooAppend'! ' to refresh LocalCache -":P luginclean-confirms removal of unused plugins; Append '! ' to auto-approve removal -" -  inFileType plugin Indent on -  toLet G: ycm_global_ycm_extra_conf= ' ~/.vim/bundle/youcompleteme/third_party/ycmd/cpp/ycm/.ycm_extra_conf.Py ' +Let G: Ycm_seed_identifiers_with_syntax=1 -Let G: ycm_confirm_extra_conf=0 theLet G: Ycm_cache_omnifunc=0 *Let G: Ycm_min_num_of_chars_for_completion=2 $Let G: Ycm_complete_in_comments=1Panax NotoginsengLet G: Ycm_complete_in_strings=1 -   the  + Setnocompatible ASOURCE $VIMRUNTIME/vimrc_example.Vim theSOURCE $VIMRUNTIME/mswin.Vim + behave Mswin - SetNobackup $ SetDiffexpr=mydiff () $function Mydiff () -Let opt ='-a--binary ' -   if&diffopt =~ ' icase ' | Let opt = opt.'-i ' | endif the   if&diffopt =~ ' Iwhite ' | Let opt = opt.'-B ' | endif -Let arg1 = V: fname_inWuyi   ifArg1 =~ ' | Let arg1 = ' "'. Arg1. ‘"' | endif theLet arg2 = V: Fname_new -   ifArg2 =~ ' | Let arg2 = ' "'. Arg2. ‘"' | endif WuLet Arg3 = V: Fname_out -   ifArg3 =~ ' | Let Arg3 = ' "'. Arg3. ‘"' | endif AboutLet EQ ="' $   if$VIMRUNTIME =~ ' -     if&sh =~ ' \<cmd' -Letcmd= ' "'. $VIMRUNTIME. ' \diff '' -Let eq = ' "' A     Else +Letcmd= Substitute ($VIMRUNTIME, "', '" ', '). ' \diff "' the endif -   Else $Letcmd= $VIMRUNTIME. ‘\diff ' the endif theSilent execute '! '.cmd. ‘ ‘ . Opt. Arg1. ‘ ‘ . Arg2. ' > '. Arg3.eq the endfunction the      Setnu! - ColorScheme Desert in syntax Enable theSyntax on the       About     SetEncoding=utf-8 the     SetFileencodings=utf-8,chinese,latin-1 the     ifHas ("Win32") the     Setfileencoding=Chinese +     Else -     SetFileencoding=utf-8 the endifBayiSOURCE $VIMRUNTIME/delmenu.Vim theSOURCE $VIMRUNTIME/menu.Vim theLanguage Messages Zh_cn.utf-8 -  -    theLet G: Nerdtreewinpos= "Left" theLet G: Nerdtreewinsize=25 theLet G: Nerdtreeshowlinenumbers=1 theLet G: Neocomplcache_enable_at_startup= 1 -  the au guienter * simalt ~x the  theMap <F2>: Nerdtreetoggle<CR>94  theLet Nerdtreeshowbookmarks=1

3. Install the Vbundle plugin Manager.

Create a directory of. Vim and Vbundle.

mkdir -p  ./.vim/bundle

下载VBundle插件管理器。
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

Download and install the plugin.

The main use of Vbundle automatic download installation features.

Start Vim 8.0.

The system is installed by default vim program is/usr/bin/vim, version 7.x. You can create a soft link in the/usr/local/bin directory, which is ranked in the previous location of the PATH environment variable, so you can override the default Vim program to activate VIM 8.0 for vim execution.

After starting Vim, execute the following command in vim and install the plug-in configured in. vimrc.

:P Lugininstall

VIM displays done after installation is complete.

4. Use the Nerdtree directory tree plugin.

Press F2 to start the Nerdtree directory tree plugin. You can see that this vim already has an auto-compile feature like Eclipse, which automatically detects the compilation errors of C + + code (the red >> symbol in the split bar, and the 46 rows and 47 lines below have two parameters that are not used in the error).


5. Use the Youcompleteme plugin.

This plugin is used to implement auto-complete function.

After the vbundle is automatically downloaded, you also need to do the following manually:

(1) Install the CMake.

sudo yum install CMake

(2) Execute the following installation script:

./install.py--clang-completer

After successful installation, the effect is as follows:

6. Use the Gdbmgr plugin.

The Gdbmgr plugin is used to debug the program using GDB in Vim. The Gdbmgr integrates common debugging windows that are more convenient and intuitive to use than GDB's layout commands.

(1) gdbmgr download.

git clone https://github.com/vim-scripts/gdbmgr.git

You can also download it at the following address:

https://www.vim.org/scripts/download_script.php?src_id=18153

(2) gdbmgr compilation.

LS ${HOME}/.VIM/BUNDLE/GDBMGR/GDBMGR/SRC

GDBMGR.C gdbmgr.h gdbmgr.o gdbmgr.so Makefile Makefile.mac
Perform make to compile.

(3) enable the Gdbmgr plugin in the. vimrc file.

Refer to the contents of the plugin Gdbmgr line in the previous. vimrc file.

(4) Test gdbmgr.

The ${HOME}/.VIM/BUNDLE/GDBMGR/GDBMGR/SRC path is added to the Ld_library_path variable first so that the system can find the gdbmgr.so dynamic library.

Export ld_library_path=${ld_library_path}:${home}/.vim/bundle/gdbmgr/gdbmgr/src/

Compile the example code in the ${home}/.vim/bundle/gdbmgr/gdbmgr/progs directory again.

After the CD is in this directory, perform vim.

Execute: di command (Debugger Initial, debugger initialization).

Does not automatically appear the expected debug interface, the main problem is that the source code and executable files are not loaded.

Workaround: The current path (.) Add the PATH variable.

Export Path=${path}:.

Start vim again and execute: di command, you can see the code and the program has been successfully loaded, the default load Prog01 and prog01.c.

Execute: The DR Command runs the debugger prog01, can set breakpoints, view variables or expression values, set watachpoints, and observe the call stack.

At this point, a vim-based C + + IDE environment is established under a CentOS7 system.

Linux Fundamentals 15: Using Vim to build a C + + development environment on CENTOS7

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.