標籤:script ast 格式 mrc dir ntp strong clu family
centos7上內建python2.7,我們需要最佳化一下python環境。
一、使用豆瓣源加速軟體安裝
pip install -i flask #使用-i 選項mkdir ~./pip && vim pip.conf #修改pip的設定檔[global]index-url = https://pypi.douban.com/simple/
二、修改.vimrc檔案
主要增加一些配置選項,例如顯示行號,一鍵執行等
vim .vimrc
set nocompatible "關閉與vi的相容模式set number "顯示行號set nowrap "不自動折行set showmatch "顯示匹配的括弧set scrolloff=3 "距離頂部和底部3行"set encoding=utf-8 "編碼set fenc=utf-8 "編碼set mouse=a "啟用滑鼠set hlsearch "搜尋高亮syntax on "文法高亮au BufNewFile,BufRead *.py\ set tabstop=4 "tab寬度\ set softtabstop=4 \ set shiftwidth=4 \ set textwidth=79 "行最大寬度\ set expandtab "tab替換為空白格鍵\ set autoindent "自動縮排\ set fileformat=unix "儲存檔案格式set foldmethod=indentset foldlevel=99map <F8> :call RunPython()<CR>func! RunPython() exec "W" if &filetype == 'python' exec "!time python2.7 %" endifendfunc
一鍵F8執行效果
三、配置vim外掛程式管理vundle
Vundle 是 Vim bundle 的簡稱,使用git來管理vim外掛程式,有了它,安裝其它外掛程式就方便很多。
建立目錄
cd ~mkdir .vimcd .vimmkdir bundle
進入目錄,下載檔案
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
然後將下列配置放在.vimrc檔案的開頭:
set nocompatible " be iMproved, requiredfiletype off " required " set the runtime path to include Vundle and initializeset rtp+=~/.vim/bundle/Vundle.vimcall vundle#begin() " let Vundle manage Vundle, requiredPlugin 'VundleVim/Vundle.vim' " All of your Plugins must be added before the following linecall vundle#end() " requiredfiletype plugin indent on " required
如果想下載某個外掛程式,比如自動縮排indentpython.vim外掛程式,需要將
Plugin 'vim-scripts/indentpython.vim'
置於call vundle#begin()和call vundle#end()之間,儲存配置後在vim中執行
:PluginInstall
四、多視窗編輯
五、安裝常用python外掛程式
編程提示外掛程式jedi-vim
pip install jedigit clone --recursive https://github.com/davidhalter/jedi-vim.git ~/.vim/bundle/jedi-vim
2.語法檢查syntastic
git clone https://github.com/vim-syntastic/syntastic.gitPlugin 'vim-syntastic/syntastic' #.vimrc中增加
3.flak8代碼風格檢查
pip install flake8https://github.com/nvie/vim-flake8.gitPlugin 'nvie/vim-flake8' #.vimrc中添加
按F7進行檢查·
4.添加樹形目錄
git clone Plugin 'scrooloose/nerdtree' #.vimrc中添加map <C-n> :NERDTreeToggle<CR> #.vimrc中添加 使用Ctrl+n快速鍵
5.縮排顯示 indentline
git clone https://github.com/Yggdroot/indentLinePlugin 'Yggdroot/indentLine' #vimrc中添加
6.vim-autopep8自動格式化代碼
pip install autopep8 git clone https://github.com/tell-k/vim-autopep8.git Plugin 'tell-k/vim-autopep8' #vimrc中添加 autocmd FileType python noremap <buffer> <F9> :call Autopep8()<CR> #使用快速鍵F9
7.auto-pairs自動補全括弧和引號
git clone Plugin 'jiangmiao/auto-pairs'
8.ctrlp.vim搜尋檔案
在vim普通模式下搜尋ctl+P即可
Plugin 'kien/ctrlp.vim'
最終,整個設定檔.vimrc如下所示:
set nocompatible " be iMproved, requiredfiletype off " required " set the runtime path to include Vundle and initializeset rtp+=~/.vim/bundle/Vundle.vimcall vundle#begin() " let Vundle manage Vundle, requiredPlugin 'VundleVim/Vundle.vim'Plugin 'davidhalter/jedi-vim'Plugin 'vim-syntastic/syntastic'Plugin 'nvie/vim-flake8'Plugin 'scrooloose/nerdtree'Plugin 'Yggdroot/indentLine'Plugin 'tell-k/vim-autopep8'Plugin 'vim-scripts/indentpython.vim'Plugin 'kien/ctrlp.vim'Plugin 'jiangmiao/auto-pairs'" All of your Plugins must be added before the following linecall vundle#end() " requiredfiletype plugin indent on " requiredset nocompatible "關閉與vi的相容模式set number "顯示行號set nowrap "不自動折行set showmatch "顯示匹配的括弧set scrolloff=3 "距離頂部和底部3行"set encoding=utf-8 "編碼set fenc=utf-8 "編碼set mouse=a "啟用滑鼠set hlsearch "搜尋高亮syntax on "文法高亮au BufNewFile,BufRead *.py\ set tabstop=2 "tab寬度\ set softtabstop=4 \ set shiftwidth=4 \ set textwidth=79 "行最大寬度\ set expandtab "tab替換為空白格鍵\ set autoindent "自動縮排\ set fileformat=unix "儲存檔案格式set foldmethod=indentset foldlevel=50map <F8> :call RunPython()<CR>func! RunPython() exec "W" if &filetype == 'python' exec "!time python2.7 %" endifendfuncmap <C-n> :NERDTreeToggle<CR>autocmd FileType python noremap <buffer> <F9> :call Autopep8()<CR>
python學習-vim外掛程式安裝