安裝步驟
1. 安裝支持python3的vim
首先是卸載raspbian自帶的vim,這個(gè)是必要,因?yàn)闃漭勺詭У膙im和 sudo apt install vim 命令安裝的vim都是默認(rèn)不支持python2/3的,這點(diǎn)通過 vim --version 即可看見python和python3前面都有“-”標(biāo)志,意思是不支持python。必須解決的原因是之后安裝的一個(gè)重要插件“YouCompleteMe”必須依賴于vim支持python3才能使用。
安裝思路很簡單,卸載和vim有關(guān)的所有軟件包后手動(dòng)下載源碼編譯安裝即可:
sudo apt-get remove vim vim-tiny vim-common vim-runtime #卸載raspbian一般自帶的vim相關(guān)軟件包
dpkg -l | grep vim #看看還有哪些vim的版本沒卸載,優(yōu)先使用“sudo apt purge 軟件包名”來卸載
#如果發(fā)現(xiàn)無法卸載的情況,可以通過“whereis 軟件包名”來查看文件所在位置并手動(dòng)刪除
#如果還出現(xiàn)無法刪除的情況可以通過“sudo -i”切換到root帳戶下刪除
安裝依賴包以防之后安裝失敗
sudo apt-get install python-dev
sudo apt-get install python3-dev
sudo apt-get install libncurses5-dev
安裝vim
git clone https://github.com/vim/vim.git #下載vim源碼包,本文寫出時(shí)是vim8
#如果下載提示失敗,可以適當(dāng)調(diào)整下git的參數(shù)以實(shí)現(xiàn)正常下載:
git config --global http.postBuffer 20000000
cd vim
./configure --with-features=huge --enable-multibyte --enable-rubyinterp=yes --enable-python3interp=yes --with-python3-config-dir=/usr/lib/python3.5/config-3.5m-arm-linux-gnueabihf --enable-perlinterp=yes --enable-luainterp=yes --enable-gui=gtk2 --enable-cscope --prefix=/usr
#在寫本文的時(shí)候只有此configure參數(shù)可以實(shí)現(xiàn)vim支持python3且安裝過程不會(huì)出錯(cuò)
sudo make &&sudo make install
對(duì)于configure有關(guān)數(shù)據(jù)做個(gè)簡單介紹:
--with-features=huge:支持最大特性
--enable-rubyinterp:打開對(duì)ruby編寫的插件的支持
--enable-pythoninterp:打開對(duì)python編寫的插件的支持
--enable-python3interp:打開對(duì)python3編寫的插件的支持
--enable-luainterp:打開對(duì)lua編寫的插件的支持
--enable-perlinterp:打開對(duì)perl編寫的插件的支持
--enable-multibyte:打開多字節(jié)支持,可以在Vim中輸入中文
--enable-cscope:打開對(duì)cscope的支持
--with-python-config-dir=/usr/lib/python2.7/config-x86_64-linux-gnu/ 指定python 路徑
--with-python-config-dir=/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu/ 指定python3路徑,但根據(jù)測(cè)試,本文需要的vim必須支持python3而不是python2,而一旦配置2,3的配置就無效了
--prefix=/usr/local/vim:指定將要安裝到的路徑(自行創(chuàng)建,但建議不知道vim默認(rèn)安裝路徑的時(shí)候最多/usr就可以了)
此時(shí)再通過命令vim --version即可查看到安裝的vim支持python3了。至此,vim安裝完成。
2. 安裝專為C/C++定制的vim插件一鍵腳本vimplus和添加一鍵編譯運(yùn)行C/C++程序快捷鍵
vimplus作者github地址:https://github.com/chxuan/vimplus
vimplus作者博客地址:
http://www.cnblogs.com/highway-9/p/5414465.html
http://www.cnblogs.com/highway-9/p/5984285.html
安裝過程在github介紹里面寫的非常詳細(xì)不多說,唯一需要注意的一點(diǎn)是,vimplus的install.sh運(yùn)行時(shí)千萬別通過sudo提權(quán),否則東西會(huì)被安裝在一個(gè)奇怪的地方而且安裝不全。
使用手冊(cè):
https://github.com/chxuan/vimplus/blob/master/help.md
因?yàn)関implus并不支持一鍵編譯安裝功能,加上每次修改過程序要運(yùn)行就得輸入兩句命令挺麻煩
gcc 文件名.c
./文件名.out
或者
gcc 文件名.c -o 制定文件名(無需后綴)
./定制文件名
在翻遍并復(fù)制粘貼國內(nèi)一堆堆的解決方法且全部失敗后,搜了些國外的方法,僅嘗試并采用其中一種方法(主要是答者解釋非常詳細(xì)):鏈接:https://stackoverflow.com/questions/2627886/how-do-i-run-a-c-program-from-vim
作者對(duì)于實(shí)現(xiàn)方法的介紹的搬運(yùn)
Use the following mapping code in your .vimrc file for compiling and running a c programming file.
map <F8> : !gcc % && ./a.out <CR>
F8 key is for run the mapping. "%" is to take the current file name.
Or, if you want to save the current file before compiling it, use
map <F8> :w <CR> :!gcc % && ./a.out <CR>
Or more ideally, if you want to use the file basename not the default 'a.out' as the executable file name, use the following:
map <F8> :w <CR> :!gcc % -o %< && ./%< <CR>
In the above command, "<" after "%" removes extension and dot (foo.c => foo), so "%<" is the file basename.
You can find this and similar infos in cmdline.txt. Command in vim:help: cmdline.txt. You can also find specific details about the use of "%" by using :help filename-modifiersin vim.
CTRL+SHIF+T調(diào)出的終端中輸入vim
按下組合鍵 ,和e (英文字母逗號(hào)和小寫字母e)打開/home/pi/.vimrc,在行末添加一下一行并保存
map <F4> : !gcc % && ./a.out <CR> #vimplus默認(rèn)F5,F7-10都有功能分配,我就選擇將編譯運(yùn)行按鍵設(shè)置為F4
其他可能能實(shí)現(xiàn)同樣功能的方法鏈接:
https://stackoverflow.com/questions/2627886/how-do-i-run-a-c-program-from-vim
https://unix.stackexchange.com/questions/7823/compiling-code-from-vim
https://stackoverflow.com/questions/18296192/vim-compile-and-run-shortcut