ubuntu下vim 安裝Vundle和YouCompleteMe
采用的系統硬體都得環境
(1)作業系統:ubuntu14.04(ubuntu16.04也可以用)
(2)vim版本:vim8
前言
對于一個Linux系統,源都是國外的,是以在國内下載下傳軟體操作,一定要更新國内的鏡像源。然後在進行其他一系列的開發和使用,如果源有問題,就會造成很多軟體下載下傳不成功等各種問題。更換成國内的鏡像源是非常關鍵而且必須的一步,為什麼同樣的操作,在别人的電腦上能執行,而你卻不能執行,很有可能就是差在這一步上了。
強烈推薦清華源,下面提供一個ubuntu清華源的官方連結,非常好用,而且可以根據ubuntu的版本選擇不同版本的源
(https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/)
更換完國内源後,按照下面的步驟,一步一步安裝YoucompleteMe插件,自動補全功能,非常強大。
1.安裝vim8
ubuntu 14.05 安裝完YouCompleteMe後不生效,提示:YouCompleteMe unavailable : requires Vim 7.4.143
經過檢索與查詢,ubuntu自帶的vim為7.4.50,需要安裝最新的vim。按照下面的指令,進行vim8的下載下傳。
sudo add-apt-repository ppa:jonathonf/vim
sudo apt update
sudo apt install vim
sudo add-apt-repository ppa:jonathonf/vim
sudo apt-get update && sudo apt-get upgrade
2.Vundle安裝及配置
(1)安裝git
sudo apt-get install git
(2)将Vundle克隆至本地使用者根目錄下的~/.vim/bundle路徑下,若無該路徑可自行建立
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
(3)配置Vundle的插件
将以下内容放至.vimrc檔案的頂部,若無.vimrc檔案,可在使用者主目錄下建立.vimrc檔案,即~/.vimrc
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" My Plugins:
Plugin 'Valloric/YouCompleteMe'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
至此,Vundle的安裝和配置檔案的設定已經完成。
3.YouCompleteMe安裝
我們已經采用的vim8了,可以再次确認一下vim版本以及是否支援Python2/3,YouCompleteMe需要VIM7.4.1578及以上版本和Python2/3的支援,安裝YouComplete前請一定确認自己的VIM版本,以及VIM是否支援Python2/3,可在終端輸入以下指令檢視
vim --version
(1)安裝cmake和相關Python頭檔案
YouCompleteMe的安裝需要cmake和python相關頭檔案的支援,可在終端下通過如下指令安裝:
sudo apt-get install build-essential cmake
sudo apt-get install python-dev python3-dev
sudo apt-get install clang
(2)YouCompleteMe的安裝
git clone https://github.com/Valloric/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe
載完成後,需要對YouComplete進行編譯安裝
cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer
發現指令無法執行,會提示執行下面指令,輸入執行
git submodule update --init --recursive
這個過程得至少半小時,耐心等待,隻要沒有提示錯誤,會一直進行,就ok
(3)編譯
cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer
那個error,不影響操作
4.YouCompleteMe配置
(1)編譯完成之後,還需要進行一些配置工作。把
~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py
這個檔案複制到
~/.vim
目錄下面
sudo cp ~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py ~/.vim
(2)在~/.vimrc配置檔案中還需添加如下配置。
let g:ycm_server_python_interpreter = '/usr/bin/python'
let g:ycm_global_ycm_extra_conf ='~/.vim/.ycm_extra_conf.py'
這樣就完成了YouCompleteMe插件的安裝和配置
5.測試
(1)建立一個test.c檔案
touch test.c
(2)用vi打開
指針也ok
注:
很多部落格和書上都是以下面的方式下載下傳YouCompleteMe。
首先打開vim,在其界面輸入如下指令進行YouCompleteMe的下載下傳
:PluginInstall
下載下傳完成後,會出現”Done!“。這一步的操作與網絡有很大的關系,是以在操作前,務必確定網絡的通暢。下載下傳完成後,需要對YouComplete進行編譯安裝。本文隻考慮對C++的自動補全,是以進入終端輸入如下指令
cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer
因為在vim下執行PluginInstall,沒有程序的反應,是以根本不知道是在下載下傳還是卡機了,而且我測試了一晚上還是沒有下載下傳成功,是以還是建議上面的方法。
參考資料:
1.https://blog.csdn.net/ZeroDegree1216/article/details/81950656
2.https://blog.csdn.net/u011529752/article/details/78462125