centos配置vim c++開發環境

jxhaha發表於2020-09-28

好久沒從0開始配置vim環境了,今天搞了一下,發現碰到好多問題,整理一下,以便下個環境能繼續用。
我的作業系統是redhat,centos7.2
vim程式碼自動提示外掛YouCompleteMe需要vim8和python3版本,centos7.2自帶的vim和python都不符合要求,需要重新安裝。
檢視vim是否支援python3,可以直接按下操作vim --version|head 如果裡面有python3且python3前面為"+",則代表支援,否則不支援,需要重新安裝vim

環境安裝涉及以下幾步
1、刪除舊的vim配置

yum remove vim-enhanced vim-common vim-filesystem vim-minimal

2、從github上下載安裝python3

wget https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tar.xz
tar -xvJf Python-3.8.6rc1.tar.xz 
cd Python-3.8.6rc1
./configure --enable-shared
make
make install

安裝後更新bash_profile

PATH=$PATH:$HOME/bin:/usr/local/bin (加這個是因為我預設是root許可權安裝, python3 make install之後的路徑預設是這裡)

3、從github上下載vim

git clone https://github.com/vim/vim.git
cd vim
export LDFLAGS="-rdynamic" 
./configure --with-features=huge  --enable-multibyte --enable-rubyinterp=yes --enable-python3interp=yes   --enable-perlinterp=yes --enable-luainterp=yes
make
make install

4、從github上下載bundle

git clone https://github.com/VundleVim/Vundle.vim.git
如果~/.vim資料夾不存在,則直接建立~/.vim/bundle
mv Vundle.vim ~/.vim/bundle/

5、從github上現在NERDTree

cd ~/.vim/bundle
 git clone https://github.com/scrooloose/nerdtree.git

6、從github上現在YouCompleteMe

YouComplete比較特殊,需要python-dev,libffi-dev, libclang-dev

 yum install python-devel
 yum install libffi-devel -y
 yum install libclang-dev
 yum install cmake

之後下載You’CompleteMe

git clone https://github.com/Valloric/YouCompleteMe.git
cd YouCompleteMe
git submodule update --init --recursive
python3 install.py --clang-completer --system-libclang

7、配置vimrc

set encoding=utf-8                                                                                                                                                                    
set nocompatible
filetype on

set completeopt=preview,menu
set cursorline
set autoindent
set ruler
set tabstop=4
set softtabstop=4
set smarttab
set number
set ignorecase
set hlsearch
set incsearch
set laststatus=2


set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'YouCompleteMe'
Plugin 'nerdtree'
call vundle#end()
filetype plugin indent on

autocmd vimenter * NERDTree
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/.ycm_extra_conf.py'
let g:ycm_seed_identifiers_with_syntax=1
let g:ycm_complete_in_strings = 1 
let g:ycm_seed_identifiers_with_syntax=1
let g:ycm_key_invoke_completion = '<C-a>'

autocmd InsertLeave * if pumvisible() == 0|pclose|endif

相關文章