centos7使用vim打造強大的pyt

編譯升級vim

centos7.3自帶的vim是7.4.*版本, YouCompleteMe需要Vim 7.4.1578+ 我這裡編譯安裝vim8.0

# 移除舊版本  sudo yum remove vim -y  # 安裝必要組件  sudo yum install ncurses-devel python-devel -y  # 下載源碼編譯安裝  git clone https://github.com/vim/vim.git  cd vim/src  # 根據自己實際情況設置編譯參數  ./configure --with-features=huge --enable-pythoninterp=yes --enable-cscope --enable-fontset --with-python-config-dir=/usr/lib64/python2.7/config --enable-python3interp=yes --with-python-config-dir=/usr/lib/python3.6/config --enable-multibyte --prefix=/usr/local/vim/    make -j2 && make install

編譯參數說明:

  • [ ] –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 路徑
  • [ ] –with-python-config-dir=/usr/lib64/python3.5/config 指定python3路徑

注意:必須帶上Python編寫插件支援,最好帶上Python路徑,否則使用時會報這個錯誤:YouCompleteMe unavailable: requires Vim compiled with Python (2.6+ or 3.6+) support

安裝完成後,vim就安裝在了/usr/local/vim/bin,添加環境變數,把該目錄加入到PATH方便terminal全局使用

[root@aiker ~]# cat /etc/profile.d/vim.sh  export PATH=$PATH:/usr/local/vim/bin/

查看版本和支援資訊:

[root@aiker ~]# vim --version  VIM - Vi IMproved 8.1 (2018 May 18, compiled Aug 20 2018 03:23:45)  Included patches: 1-299  Compiled by root@aiker  Huge version without GUI.  Features included (+) or not (-):  +acl               +extra_search      +mouse_netterm     +tag_old_static  +arabic            +farsi             +mouse_sgr         -tag_any_white  +autocmd           +file_in_path      -mouse_sysmouse    -tcl  +autochdir         +find_in_path      +mouse_urxvt       +termguicolors  -autoservername    +float             +mouse_xterm       +terminal  -balloon_eval      +folding           +multi_byte        +terminfo  +balloon_eval_term -footer            +multi_lang        +termresponse  -browse            +fork()            -mzscheme          +textobjects  ++builtin_terms    +gettext           +netbeans_intg     +timers  +byte_offset       -hangul_input      +num64             +title  +channel           +iconv             +packages          -toolbar  +cindent           +insert_expand     +path_extra        +user_commands  -clientserver      +job               -perl              +vartabs  -clipboard         +jumplist          +persistent_undo   +vertsplit  +cmdline_compl     +keymap            +postscript        +virtualedit  +cmdline_hist      +lambda            +printer           +visual  +cmdline_info      +langmap           +profile           +visualextra  +comments          +libcall           +python            +viminfo  +conceal           +linebreak         -python3           +vreplace  +cryptv            +lispindent        +quickfix          +wildignore  +cscope            +listcmds          +reltime           +wildmenu  +cursorbind        +localmap          +rightleft         +windows  +cursorshape       -lua               -ruby              +writebackup  +dialog_con        +menu              +scrollbind        -X11  +diff              +mksession         +signs             -xfontset  +digraphs          +modify_fname      +smartindent       -xim  -dnd               +mouse             +startuptime       -xpm  -ebcdic            -mouseshape        +statusline        -xsmp  +emacs_tags        +mouse_dec         -sun_workshop      -xterm_clipboard  +eval              -mouse_gpm         +syntax            -xterm_save  +ex_extra          -mouse_jsbterm     +tag_binary     system vimrc file: "$VIM/vimrc"       user vimrc file: "$HOME/.vimrc"   2nd user vimrc file: "~/.vim/vimrc"        user exrc file: "$HOME/.exrc"         defaults file: "$VIMRUNTIME/defaults.vim"    fall-back for $VIM: "/usr/local/vim/share/vim"  Compilation: gcc -std=gnu99 -c -I. -Iproto -DHAVE_CONFIG_H     -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1  Linking: gcc -std=gnu99   -L/usr/local/lib -Wl,--as-needed -o vim        -lm -ltinfo -lnsl  -lselinux  -ldl    -L/usr/lib64/python2.7/config -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic  

安裝應用:

pip install pep8 flake8 pyflakes isort yapf autopep8 powerline-status

安裝Vundle和YouCompleteMe

Vundle是Vim的插件管理工具,官方文檔:https://github.com/VundleVim/Vundle.vim

安裝步驟很簡單:

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

添加顏色主題方案

我這裡使用monokai 配色方案 :https://github.com/sickill/vim-monokai

下載對應的monokai.vim 文件 放到 ~/.vim/colors/ 即可

mkdir ~/.vim/colors  wget -O ~/.vim/colors/monokai.vim https://raw.githubusercontent.com/sickill/vim-monokai/master/colors/monokai.vim

克隆我的github .vimrc

git clone https://github.com/donxan/vim_python_IDE.git

安裝插件

打開任意一vim編輯窗口,使用命令模式鍵入以下命令即可實現對應功能

:PluginList - 列出所有已配置的插件  :PluginInstall - 安裝插件,追加 `!` 用以更新或使用  :PluginUpdate:PluginSearch foo - 搜索 foo ; 追加 `!` 清除本地快取  :PluginClean - 清除未使用插件,需要確認; 追加 `!` 自動批准移除未使用插件  :h vundle 獲取更多細節和wiki以及FAQ

或者通過以下快速安裝:

 vim +PluginInstall +qall

附加

增加clang:添加C語言家族語法補全功能

sudo yum install cmake -y  cd ~/.vim/plugin/YouCompleteMe  ./install.py --clang-completer

可能出現的問題:

The ycmd server SHUT DOWN (restart with ':YcmRestartServer').  Unexpected error while loading the YCM core library.  Use the ':YcmToggleLogs' command to check the logs.

1.重裝YouCompleteMe

python YouCompleteMe/install.py --clang-completer --racer-completer

2.如果安裝YouCompleteMe過程中出現異常

curl -sSf https://static.rust-lang.org/rustup.sh | sh

安裝成功後再重試上述步驟1

效果如圖:

Tags: