安裝Vim 8.0
yum install ncurses-devel wget https://github.com/vim/vim/archive/master.zip unzip master.zip cd vim-master cd src/ ./configure make sudo make install vim
注:make clean僅僅是清除之前編譯的可執行文件及配置文件,而make distclean要清除所有生成的文件。
注:編譯安裝vim8.0,添加python支持 不能同時支持二者
獲得python支持,編譯時得加入參數
./configure --with-features=huge --enable-python3interp --enable-pythoninterp --with-python-config-dir=/usr/lib64/python2.7/config/ --enable-rubyinterp --enable-luainterp --enable-perlinterp --with-python3-config-dir=/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu/ --enable-multibyte --enable-cscope --prefix=/usr/local/vim/
參數說明如下:
--with-features=huge:支持最大特性
--enable-rubyinterp:打開對ruby編寫的插件的支持
--enable-pythoninterp:打開對python編寫的插件的支持
--enable-python3interp:打開對python3編寫的插件的支持
--enable-luainterp:打開對lua編寫的插件的支持
--enable-perlinterp:打開對perl編寫的插件的支持
--enable-multibyte:打開多字節支持,可以在Vim中輸入中文
--enable-cscope:打開對cscope的支持
--with-python-config-dir=/usr/lib64/python2.7/config 指定python config路徑
--with-python-config-dir=/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu/ 指定python3 config路徑
--prefix=/usr/local/vim:指定將要安裝到的路徑(自行創建)
對perl組件支持的問題
在編譯perl組件支持時,出現如下錯誤:
/bin/perl -e 'unless ( $] >= 5.005 ) { for (qw(na defgv errgv)) { print "#define PL_$_ $_\n" }}' > auto/if_perl.c /bin/perl /usr/share/perl5/ExtUtils/xsubpp -prototypes -typemap \ /usr/share/perl5/ExtUtils/typemap if_perl.xs >> auto/if_perl.c Can't open perl script "/usr/share/perl5/ExtUtils/xsubpp": No such file or directory Makefile:2453: recipe for target 'auto/if_perl.c' failed make[1]: *** [auto/if_perl.c] Error 2 make[1]: Leaving directory '/home/$usr/vim/src/vim74/src' Makefile:26: recipe for target 'first' failed make: *** [first] Error 2
解決:
yum install perl-ExtUtils*
找了下,發現perl5的$lib路徑和原先系統的竟然不一樣了,在$PELR5/vendor_perl/ExtUtil/中才有連接文件xsubpp。
接着修改了編譯的指向路徑,接着編譯,卻報錯:
objects/buffer.o: In function `free_buffer': /home/$usr/vim/src/vim74/src/buffer.c:661: undefined reference to `perl_buf_free' objects/ex_docmd.o:(.rodata+0x4678): undefined reference to `ex_perl' objects/ex_docmd.o:(.rodata+0x4690): undefined reference to `ex_perldo' objects/window.o: In function `win_free': /home/$usr/vim/src/vim74/src/window.c:4554: undefined reference to `perl_win_free' objects/main.o: In function `getout': /home/$usr/vim/src/vim74/src/main.c:1488: undefined reference to `perl_end' collect2: error: ld returned 1 exit status link.sh: Linking failed Makefile:1733: recipe for target 'vim' failed make[1]: *** [vim] Error 1 make[1]: Leaving directory '/home/$USR/vim/src/vim74/src' Makefile:26: recipe for target 'first' failed make: *** [first] Error 2
檢查src/auto/中的if_perl.c文件,發現竟然是空得,生成失敗了。
根據makefile或者第一個報錯的指引,找到生成if_perl.c的命令,手動生成即可:
/bin/perl -e 'unless ( $] >= 5.005 ) { for (qw(na defgv errgv)) { print "#define PL_$_ $_\n" }}' > auto/if_perl.c /bin/perl /usr/share/perl5/ExtUtils/xsubpp -prototypes -typemap \ /usr/share/perl5/ExtUtils/typemap if_perl.xs >> auto/if_perl.c
注意xsubpp的路徑。
如果出現問題請安裝python-dev 再執行上面命令
sudo yum install python-dev
sudo yum install python3-dev
sudo yum install libncurses5-dev
確保 vim 支持 python 2/3 腳本

從上圖可以看出老夫的 vim 版本是 8.0.49 且支持 python3 腳本但不支持 python2 腳本(截圖的倒數第 7,8 行)
如果你的打印結果中沒有相關 python 腳本信息,還可以在 vim 中鍵入命令 :echo has('python') || has('python3')
,若結果是 1 則證明是支持的。
若不論是 vim 版本不滿足條件或者是不支持 python 腳本,那么就需要從源碼編譯安裝 vim 了,