一黄伊、源碼編譯安裝vim8.0
配置epel源
yum install epel-release
安裝python3,以及vim8.0編譯環(huán)境
yum install -y gcc python34 python34-devel ncurses-devel wget libzip bzip2 git
下載vim8.0
wget ftp://ftp.vim.org/pub/vim/unix/vim-8.0.tar.bz2
tar -jxf vim-8.0.tar.bz2
cd vim80
編譯安裝并支持python3
make clean
./configure --prefix=/opt/vim8 --enable-fail-if-missing --enable-python3interp --enable-multibyte --enable-fontset --with-features=huge
make
make install
查看安裝的vim信息
/opt/vim8/bin/vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Mar 15 2017 23:40:14)
包含補(bǔ)丁: 1-69
編譯者 root@erick
巨型版本 無(wú)圖形界面泪酱。 可使用(+)與不可使用(-)的功能:
+acl +file_in_path +mouse_sgr +tag_old_static
+arabic +find_in_path -mouse_sysmouse -tag_any_white
+autocmd +float +mouse_urxvt -tcl
-balloon_eval +folding +mouse_xterm +termguicolors
-browse -footer +multi_byte +terminfo
++builtin_terms +fork() +multi_lang +termresponse
+byte_offset +gettext -mzscheme +textobjects
+channel -hangul_input +netbeans_intg +timers
+cindent +iconv +num64 +title
-clientserver +insert_expand +packages -toolbar
-clipboard +job +path_extra +user_commands
+cmdline_compl +jumplist -perl +vertsplit
+cmdline_hist +keymap +persistent_undo +virtualedit
+cmdline_info +lambda +postscript +visual
+comments +langmap +printer +visualextra
+conceal +libcall +profile +viminfo
+cryptv +linebreak -python +vreplace
+cscope +lispindent +python3 +wildignore
+cursorbind +listcmds +quickfix +wildmenu
+cursorshape +localmap +reltime +windows
+dialog_con -lua +rightleft +writebackup
+diff +menu -ruby -X11
+digraphs +mksession +scrollbind -xfontset
-dnd +modify_fname +signs -xim
-ebcdic +mouse +smartindent -xpm
+emacs_tags -mouseshape +startuptime -xsmp
+eval +mouse_dec +statusline -xterm_clipboard
+ex_extra -mouse_gpm -sun_workshop -xterm_save
+extra_search -mouse_jsbterm +syntax
+farsi +mouse_netterm +tag_binary
系統(tǒng) vimrc 文件: "$VIM/vimrc"
用戶 vimrc 文件: "$HOME/.vimrc"
第二用戶 vimrc 文件: "~/.vim/vimrc"
用戶 exrc 文件: "$HOME/.exrc"
defaults file: "$VIMRUNTIME/defaults.vim"
$VIM 預(yù)設(shè)值: "/opt/vim8/share/vim"
編譯方式: gcc -c -I. -Iproto -DHAVE_CONFIG_H -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
鏈接方式: gcc -L/usr/local/lib -Wl,--as-needed -o vim -lm -ltinfo -lnsl -ldl -L/usr/lib64/python3.4/config-3.4m -lpython3.4m -lpthread -ldl -lutil -lm
設(shè)置vim8的配置文件
cp /opt/vim8/share/vim/vim80/vimrc_example.vim /opt/vim8/share/vim/vimrc
將vim8做軟連接到/usr/bin下為vim8_py3,方便直接調(diào)用
ln -s /opt/vim8/bin/vim /usr/bin/vim8_py3
二还最、配置vim for python
創(chuàng)建目錄并clone vundle源代碼
mkdir /opt/vim8/share/vim/bundle
git clone https://github.com/gmarik/vundle.git /opt/vim8/share/vim/bundle/vundle.vim
編輯配置文件vimrc添加如下內(nèi)容
vim /opt/vim8/share/vim/vimrc
"去除VI一致性,必須
set nocompatible
"必須
filetype off
"設(shè)置Vundle的運(yùn)行路徑
set rtp+=/opt/vim8/share/vim/bundle/Vundle.vim
"設(shè)置插件的安裝路徑,vundle插件起始標(biāo)志
call vundle#begin('/opt/vim8/share/vim/bundle')
"讓vundle管理插件版本
Plugin 'VundleVim/Vundle.vim'
"你的所有插件需要在下面這行之前
call vundle#end()
"加載vim自帶和插件相應(yīng)的語(yǔ)法和文件類型相關(guān)腳本
filetype plugin indent on
然后運(yùn)行vim8_py3墓阀,在Normal模式下運(yùn)行命令PluginList
vim8_py3
回車后一個(gè)新的窗口即Vundle,會(huì)列出你安裝的所有插件
運(yùn)行PluginInstall會(huì)安裝列表中的插件
注:刪除插件只需要在vimrc配置文件中注釋掉插件拓轻,在vim中用PluginClean進(jìn)行清理
下面會(huì)安裝不同的包斯撮,你只需將它們添加到vimrc中,然后再vim運(yùn)行PluginInstall扶叉,下面將介紹一些能用到的插件
- nerdtree插件勿锅,nerdtree是一個(gè)在vim中新窗口顯示的文件瀏覽器,在vimrc中添加如下內(nèi)容
"添加nerdtree插件
Bundle 'scrooloose/nerdtree'
"設(shè)置按F2啟動(dòng)NerdTree
map <F2> :NERDTreeToggle<CR>
"隱藏目錄樹(shù)中的.pyc文件
let NERDTreeIgnore=['\.pyc$', '\~$'] "ignore files in NERDTree
可以先用PluginList查看下插件枣氧,再用PluginInstall安裝
在normal模式下溢十,按F2可以開(kāi)啟或者關(guān)閉樹(shù)形結(jié)構(gòu),可以用鼠標(biāo)點(diǎn)選文件打開(kāi)达吞,是不是很方便张弛!
- jedi-vim代碼補(bǔ)全插件,擁有強(qiáng)大的提示功能
需要用pip安裝jedi
yum install python34-pip
pip3 install jedi
在vimrc中添加如下內(nèi)容,然后再vim中執(zhí)行PluginInstall安裝
"添加jedi-vim代碼補(bǔ)全插件
Plugin 'davidhalter/jedi-vim'
效果如下圖:
- YouCompleteMe另一個(gè)十分強(qiáng)大的代碼補(bǔ)全插件,我更喜歡這個(gè)酪劫,jedi-vim在我的vim中總是有點(diǎn)小瑕疵吞鸭,用的不是很順手。
"添加YouCompleteMe代碼補(bǔ)全插件
Plugin 'Valloric/YouCompleteMe'
"youcompleteme 默認(rèn)tab s-tab 和自動(dòng)補(bǔ)全沖突
""let g:ycm_key_list_select_completion=['<c-n>']
let g:ycm_key_list_select_completion = ['<Down>']
"let g:ycm_key_list_previous_completion=['<c-p>']
let g:ycm_key_list_previous_completion = ['<Up>']
"關(guān)閉加載.ycm_extra_conf.py提示
let g:ycm_confirm_extra_conf=0
" 開(kāi)啟 YCM 基于標(biāo)簽引擎
let g:ycm_collect_identifiers_from_tags_files=1
" 從第2個(gè)鍵入字符就開(kāi)始羅列匹配項(xiàng)
let g:ycm_min_num_of_chars_for_completion=2
" 禁止緩存匹配項(xiàng),每次都重新生成匹配項(xiàng)
let g:ycm_cache_omnifunc=0
" 語(yǔ)法關(guān)鍵字補(bǔ)全
let g:ycm_seed_identifiers_with_syntax=1
"force recomile with syntastic
nnoremap <F5> :YcmForceCompileAndDiagnostics<CR>
"nnoremap <leader>lo :lopen<CR> "open locationlist
"nnoremap <leader>lc :lclose<CR> "close locationlist
inoremap <leader><leader> <C-x><C-o>
"在注釋輸入中也能補(bǔ)全
let g:ycm_complete_in_comments = 1
"在字符串輸入中也能補(bǔ)全
let g:ycm_complete_in_strings = 1
"注釋和字符串中的文字也會(huì)被收入補(bǔ)全
let g:ycm_collect_identifiers_from_comments_and_strings = 0
當(dāng)YouCompleteMe在vim安裝時(shí)間會(huì)有點(diǎn)長(zhǎng)契耿,需要耐心等待瞒大,安裝完成后還需要進(jìn)入到目錄進(jìn)行編譯
cd /opt/vim8/share/vim/bundle/YouCompleteMe/
python3 install.py --clang-completer
編譯結(jié)束后就可以使用了,如下圖搪桂,和jedi-vim還是有些不一樣的:
- syntastic一款python語(yǔ)法檢測(cè)插件
"python語(yǔ)法檢測(cè)
Plugin 'scrooloose/syntastic'
"添加PEP8代碼風(fēng)格檢查
Plugin 'nvie/vim-flake8'
- 配色方案
"配色方案
Plugin 'jnurmine/Zenburn'
Plugin 'altercation/vim-colors-solarized'
"設(shè)置主題顏色透敌,以及設(shè)置快捷鍵F5
if has('gui_running')
set background=dark
colorscheme solarized
else
colorscheme zenburn
endif
call togglebg#map("<F5>")
- 代碼折疊插件
"代碼折疊插件
Plugin 'tmhedberg/SimpylFold'
"開(kāi)啟代碼折疊
set foldmethod=indent
set foldlevel=99
"設(shè)置快捷鍵為空格
noremap <space> za
"顯示折疊代碼的文檔字符串
let g:SimpylFold_docstring_preview=1
- 自動(dòng)縮進(jìn)
"自動(dòng)縮進(jìn)
Plugin 'vim-scripts/indentpython.vim'
- 文件搜索
"在vim的normal模式下搜索文件
Plugin 'kien/ctrlp.vim'
后續(xù)還會(huì)有一些補(bǔ)充盯滚,附上vimrc配置文件內(nèi)容
set nocompatible " required
filetype off " required
"設(shè)置Vundle的運(yùn)行路徑
set rtp+=/opt/vim8/share/vim/bundle/Vundle.vim
"設(shè)置插件的安裝路徑,vundle插件起始標(biāo)志
call vundle#begin('/opt/vim8/share/vim/bundle')
"讓vundle管理插件版本
Plugin 'VundleVim/Vundle.vim'
"添加nerdtree插件
Plugin 'scrooloose/nerdtree'
"使用tab鍵切換窗口與目錄樹(shù)
Plugin 'jistr/vim-nerdtree-tabs'
"添加jedi-vim代碼補(bǔ)全插件
"Plugin 'davidhalter/jedi-vim'
Plugin 'Valloric/YouCompleteMe'
"python語(yǔ)法檢測(cè)
Plugin 'scrooloose/syntastic'
"添加PEP8代碼風(fēng)格檢查
Plugin 'nvie/vim-flake8'
"配色方案
Plugin 'jnurmine/Zenburn'
Plugin 'altercation/vim-colors-solarized'
"代碼折疊插件
Plugin 'tmhedberg/SimpylFold'
"自動(dòng)縮進(jìn)
Plugin 'vim-scripts/indentpython.vim'
"在vim的normal模式下搜索文件
Plugin 'kien/ctrlp.vim'
"Powerline狀態(tài)欄
Plugin 'Lokaltog/powerline', {'rtp': 'powerline/bindings/vim/'}
"你的所有插件需要在下面這行之前
call vundle#end()
"設(shè)置分割窗口
set splitbelow
set splitright
"設(shè)置窗口移動(dòng)快捷鍵
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
"設(shè)置按F2啟動(dòng)NerdTree
map <F2> :NERDTreeToggle<CR>
"youcompleteme 默認(rèn)tab s-tab 和自動(dòng)補(bǔ)全沖突
""let g:ycm_key_list_select_completion=['<c-n>']
let g:ycm_key_list_select_completion = ['<Down>']
"let g:ycm_key_list_previous_completion=['<c-p>']
let g:ycm_key_list_previous_completion = ['<Up>']
"關(guān)閉加載.ycm_extra_conf.py提示
let g:ycm_confirm_extra_conf=0
" 開(kāi)啟 YCM 基于標(biāo)簽引擎
let g:ycm_collect_identifiers_from_tags_files=1
" 從第2個(gè)鍵入字符就開(kāi)始羅列匹配項(xiàng)
let g:ycm_min_num_of_chars_for_completion=2
" 禁止緩存匹配項(xiàng),每次都重新生成匹配項(xiàng)
let g:ycm_cache_omnifunc=0
" 語(yǔ)法關(guān)鍵字補(bǔ)全
let g:ycm_seed_identifiers_with_syntax=1
"force recomile with syntastic
nnoremap <F5> :YcmForceCompileAndDiagnostics<CR>
"nnoremap <leader>lo :lopen<CR> "open locationlist
"nnoremap <leader>lc :lclose<CR> "close locationlist
inoremap <leader><leader> <C-x><C-o>
"在注釋輸入中也能補(bǔ)全
let g:ycm_complete_in_comments = 1
"在字符串輸入中也能補(bǔ)全
let g:ycm_complete_in_strings = 1
"注釋和字符串中的文字也會(huì)被收入補(bǔ)全
let g:ycm_collect_identifiers_from_comments_and_strings = 0
"隱藏目錄樹(shù)種的.pyc文件
let NERDTreeIgnore=['\.pyc$', '\~$'] "ignore files in NERDTree
"設(shè)置主題顏色,以及設(shè)置快捷鍵F5
if has('gui_running')
set background=dark
colorscheme solarized
else
colorscheme zenburn
endif
call togglebg#map("<F5>")
"開(kāi)啟代碼折疊
set foldmethod=indent
set foldlevel=99
"設(shè)置快捷鍵為空格
noremap <space> za
"顯示折疊代碼的文檔字符串
let g:SimpylFold_docstring_preview=1
"python代碼縮進(jìn)PEP8風(fēng)格
au BufNewFile,BufRead *.py,*.pyw set tabstop=4
au BufNewFile,BufRead *.py,*.pyw set softtabstop=4
au BufNewFile,BufRead *.py,*.pyw set shiftwidth=4
au BufNewFile,BufRead *.py,*.pyw set textwidth=79
au BufNewFile,BufRead *.py,*.pyw set expandtab
au BufNewFile,BufRead *.py,*.pyw set autoindent
au BufNewFile,BufRead *.py,*.pyw set fileformat=unix
"對(duì)其他文件類型設(shè)置au命令
au BufNewFile,BufRead *.js, *.html, *.css set tabstop=2
au BufNewFile,BufRead *.js, *.html, *.css set softtabstop=2
au BufNewFile,BufRead *.js, *.html, *.css set shiftwidth=2
"高亮顯示行偉不必要的空白字符
highlight Whitespace ctermbg=red guibg=red
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match Whitespace /\s\+$\ \+/
"設(shè)置行號(hào)顯示
set nu
"設(shè)置utf-8編碼
set encoding=utf-8
let python_highlight_all=1
syntax on
filetype plugin indent on