此操作來自以下連結學來
配置vim+python開發環境
https://realpython.com/blog/python/vim-and-python-a-match-made-in-heaven/
解決上文中py檔案格式配置報錯
http://stackoverflow.com/questions/11087041/gvim-to-custom-highlight-group-in-vimrc-not-working
系統環境[[email protected] ~]$ cat /etc/redhat-release
CentOS release 6.8 (Final)
[[email protected] ~]$ uname -a
Linux localhost.jiel 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
vim環境[[email protected] ~]$ vim --version
輸出中一定要有+python 選項
開始安裝
安裝基本環境資訊
安裝epel倉庫[[email protected] ~]$ sudo yum install epel-release
安裝基本軟體[[email protected] ~]$ sudo yum install vim python python34 python-devel python34-devel git curl wget
安裝python-pip[[email protected] ~]$ curl -O https://bootstrap.pypa.io/get-pip.py
[[email protected] ~]$ sudo python get-pip.py
下載下傳vundle[[email protected] ~]$ git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
建立配置檔案[[email protected] ~]$ touch ~/.vimrc
[[email protected] ~]$ vim .vimrc
填入這些基本配置set nocompatible " required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
"
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
"
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
"
" Add all your plugins here (note older versions of Vundle used Bundle
" instead of Plugin)
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
進入vim執行
:PluginInstall
完成後 基本設定就成功了
先開始安裝最大的一個插件
這是一個用于代碼補全的重要性也是杠杠的連結Bundle 'Valloric/YouCompleteMe'
把這個填入.vimrc裡面
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5yM2czN5EDM0MzMfNXL08FctdXLz8Vb31CM4BDM18Fa31yZuBnL0YTOBVGUkBjb5QzQBFUTiJULEpmaWBVaxw0bpt0dvwVNy8CXEhzLcFDMN9CXyAzcml3dvwVbvNmLvR3YxUjL1M3Lc9CX6MHc0RHaiojIsJye.png)
再次執行:PluginInstall
進行一些設定避免補全視窗出問題
避免視窗丢失let g:ycm_python_binary_path = 'python'
let g:ycm_autoclose_preview_window_after_completion=1
map g :YcmCompleter GoToDefinitionElseDeclaration
設定顯示行号
set nu
設定編碼
set encoding=utf8
現在設定分屏
set splitbelow
set splitright
映射分屏快捷鍵
"split navigations
nnoremap
nnoremap
nnoremap
nnoremap
啟用折疊
set foldmethod=indent
set foldlevel=99
映射空格鍵折疊
nnoremap za
自帶折疊有時候很頭疼安裝一個折疊插件
Plugin 'tmhedberg/SimpylFold'
設定顯示折疊行字元串
let g:SimpylFold_docstring_preview=1
設定py代碼格式PEP8
原文這裡後面沒有|會報錯
au BufNewFile,BufRead *.py
\ set tabstop=4|
\ set softtabstop=4|
\ set shiftwidth=4|
\ set textwidth=79|
\ set expandtab|
\ set autoindent|
\ set fileformat=unix
安裝一個自動縮進插件連結
Plugin 'vim-scripts/indentpython.vim'
标記多餘的空格
原文這裡也是少了一行聲明highlight
highlight BadWhitespace ctermbg=red guibg=darkred
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/
設定C-n 打開目錄樹
map :NERDTreeToggle
添加一個文法高亮插件連結
Plugin 'scrooloose/syntastic'
添加一個目錄樹插件連結
Plugin 'scrooloose/nerdtree'
添加一個C-P搜尋插件連結
Plugin 'kien/ctrlp.vim'
添加一個git內建連結
Plugin 'tpope/vim-fugitive'
添加一個狀态欄插件連結
Plugin 'Lokaltog/powerline', {'rtp': 'powerline/bindings/vim/'}
最後執行安裝
:PluginInstall
完成後就可以開始痛苦的适應之路了