標籤:pdb 說明 字串 install swa python解譯器 pil iconv gnu
編譯升級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.gitcd vim/src# 根據自己實際情況設定編譯參數./configure --with-features=huge --=yes --enable-cscope --enable-fontset --with-python-config-dir=/usr/lib64/python2.7/config –enable-python3interp --with-python-config-dir=/usr/lib/python3.6/config --enable-multibyte --with-features=huge --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全域使用
[[email protected] ~]# cat /etc/profile.d/vim.sh export PATH=$PATH:/usr/local/vim/bin/
查看版本和支援資訊:
[[email protected] ~]# vim --versionVIM - Vi IMproved 8.1 (2018 May 18, compiled Aug 20 2018 03:23:45)Included patches: 1-299Compiled by [email protected]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/colorswget -O ~/.vim/colors/monokai.vim https://raw.githubusercontent.com/sickill/vim-monokai/master/colors/monokai.vim
vim .vimrc
清空後更改為如下內容:
set encoding=utf-8"去掉vi的一致性"set nocompatible"顯示行號""set numberset nobackupset nowbset noswapfileset noundofileset showcmd" 隱藏捲軸" "set guioptions-=r "set guioptions-=L"set guioptions-=b"隱藏頂部標籤欄""set showtabline=0"設定字型""set guifont=Monaco:h13 syntax on "開啟文法高亮""let g:solarized_termcolors=256 "solarized主題設定在終端下的設定"set background=dark "設定背景色""colorscheme roncolorscheme monokaiset nowrap "設定不折行"set fileformat=unix "設定以unix的格式儲存檔案"set cindent "設定C樣式的縮排格式"set tabstop=4 "設定table長度"set softtabstop=4set noexpandtabset shiftwidth=4 "同上"set showmatch "顯示匹配的括弧"set scrolloff=5 "距離頂部和底部5行"set laststatus=2 "命令列為兩行"set fenc=utf-8 "檔案編碼"set backspace=2set mouse=c "啟用滑鼠"set selection=exclusiveset selectmode=mouse,key"set matchtime=5set ignorecase "忽略大小寫""set incsearchset hlsearch "高亮搜尋項""set noexpandtab "不允許擴充table"set whichwrap+=<,>,h,lset autoread"set cursorline "反白當前行""set cursorcolumn "反白當前列"" C++ partset exrcset secureaugroup project autocmd! autocmd BufRead,BufNewFile *.h,*.c set filetype=c.doxygen autocmd BufRead,BufNewFile *.hpp,*.cpp set filetype=cpp.doxygenaugroup ENDset makeprg=make\ -C\ -j64nnoremap <F3> :make!<cr>"Vundlefiletype offset rtp+=~/.vim/bundle/Vundle.vimcall vundle#begin()Plugin ‘VundleVim/Vundle.vim‘Plugin ‘Valloric/YouCompleteMe‘Plugin ‘Lokaltog/vim-powerline‘Plugin ‘scrooloose/nerdtree‘Plugin ‘Yggdroot/indentLine‘Plugin ‘jiangmiao/auto-pairs‘Plugin ‘tell-k/vim-autopep8‘Plugin ‘scrooloose/nerdcommenter‘Plugin ‘Tagbar‘Plugin ‘Lokaltog/powerline‘, {‘rtp‘: ‘powerline/bindings/vim/‘}call vundle#end()filetype plugin indent on"按F5運行python"map <F5> :Autopep8<CR> :w<CR> :call RunPython()<CR>function RunPython() let mp = &makeprg let ef = &errorformat let exeFile = expand("%:t") setlocal makeprg=python\ -u set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m silent make % copen let &makeprg = mp let &errorformat = efendfunction" 設定tagbar的視窗寬度let g:tagbar_width=30" 映射Tagbar的快速鍵,按F6自動開啟map <F6> :TagbarToggle<CR>"按F9運行python調試"map <F9> :Autopep8<CR> :w<CR> :call RunPythonDebug()<CR>function RunPythonDebug() let mp = &makeprg let ef = &errorformat let exeFile = expand("%:t") setlocal makeprg=python\ -m\ pdb set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m silent make % copen let &makeprg = mp let &errorformat = efendfunction"YouCompleteMe"預設設定檔路徑"let g:ycm_global_ycm_extra_conf = ‘~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py‘"開啟vim時不再詢問是否載入ycm_extra_conf.py配置"let g:ycm_confirm_extra_conf=0set completeopt=longest,menu"python解譯器路徑"let g:ycm_path_to_python_interpreter=‘/usr/bin/python‘"是否開啟語義補全"let g:ycm_seed_identifiers_with_syntax=1"是否在注釋中也開啟補全"let g:ycm_complete_in_comments=1let g:ycm_collect_identifiers_from_comments_and_strings = 0"開始補全的字元數"let g:ycm_min_num_of_chars_for_completion=2"補全後自動關機預覽視窗"let g:ycm_autoclose_preview_window_after_completion=1" 禁止緩衝匹配項,每次都重建匹配項"let g:ycm_cache_omnifunc=0"字串中也開啟補全"let g:ycm_complete_in_strings = 1"離開插入模式後自動關閉預覽視窗"autocmd InsertLeave * if pumvisible() == 0|pclose|endif"斷行符號即選中當前項""inoremap <expr> <CR> pumvisible() ? ‘<C-y>‘ : ‘\<CR>‘ "上下左右鍵行為"inoremap <expr> <Down> pumvisible() ? ‘\<C-n>‘ : ‘\<Down>‘inoremap <expr> <Up> pumvisible() ? ‘\<C-p>‘ : ‘\<Up>‘inoremap <expr> <PageDown> pumvisible() ? ‘\<PageDown>\<C-p>\<C-n>‘ : ‘\<PageDown>‘inoremap <expr> <PageUp> pumvisible() ? ‘\<PageUp>\<C-p>\<C-n>‘ : ‘\<PageUp>‘"YouCompleteMe clang settingslet g:clang_format#style_options = { \ "AccessModifierOffset" : -4, \ "AllowShortIfStatementsOnASingleLine" : "true", \ "AlwaysBreakTemplateDeclarations" : "true", \ "Standard" : "C++11"}let g:clang_format#auto_format=1"Nerd tree"F2開啟和關閉樹"map <F2> :NERDTreeToggle<CR>let NERDTreeChDirMode=1"顯示書籤"let NERDTreeShowBookmarks=1"設定忽略檔案類型"let NERDTreeIgnore=[‘\~$‘, ‘\.pyc$‘, ‘\.swp$‘]"視窗大小"let NERDTreeWinSize=25"縮排指示線"let g:indentLine_char=‘┆‘let g:indentLine_enabled = 1"autopep8設定"let g:autopep8_disable_show_diff=1autocmd Filetype python noremap <buffer> <F8> :call Autopep8()<CR>map <F4> <leader>ci <CR>
安裝外掛程式
開啟任意一vim編輯視窗,使用命令模式鍵入以下命令即可實現對應功能
:PluginList - 列出所有已配置的外掛程式:PluginInstall - 安裝外掛程式,追加 `!` 用以更新或使用:PluginUpdate:PluginSearch foo - 搜尋 foo ; 追加 `!` 清除本機快取:PluginClean - 清除未使用外掛程式,需要確認; 追加 `!` 自動批准移除未使用外掛程式:h vundle 擷取更多細節和wiki以及FAQ
或者通過以下快速安裝:
vim +PluginInstall +qall
附加
增加clang:添加C語言家族文法補全功能
sudo yum install cmake -ycd ~/.vim/plugin/YouCompleteMe ./install.py --clang-completer
效果
centos7使用vim打造強大的python IDE