在前面文章中介紹的關於vim基礎插件之上加上一款專門為讀寫python程序的插件-Python-mode. 顧名思義,就是讓vim在python模式下運行。這里介紹這款插件的功能以及如何使用。
本文主要摘錄Python-mode的幫助文檔中個人覺得用到較多的並且比較有意義的內容。
Introduction
Python-mode: includes libraries such as pylint, rope, pydoc, pyflakes, pep8, and mccabe。 Python-mode通過集成了多款插件來實現強大的功能。
Install
用Neobundle在vimrc中加入如下代碼,或者直接下載解壓.vim/plugin目錄下
Bundle 'klen/python-mode'
Function
python-mode的功能和配置非常多,但大多數只需要使用默認配置即可。總結幫助文檔(help pymode),可以通過介紹他的配置項可以了解它的功能:
1. Turn on the Plugin:
let g:pymode = 1 “關閉和打開python-mode插件
2. Choose python version:
let g:pymode_python = 'python' "or python3, disable. “選擇python的版本
3. PEP8-compatible python indent:
let g:pymode_indent = 1 ”使用縮進的風格為pep8
4. Enable pymode folding:
let g:pymode_folding = 1 “使能折疊功能
5. Show Document:
let g:pymode_doc = 1 " 通過命令:PymodeDoc arg查閱文檔
let g:pymode_doc_bind = 'K' "光標移到參數上面按快捷鍵K
6. Run code:
let g:pymode_run = 1
let g:pymode_run_bind = '<leader>r' ”在vim中運行
7. Add breakpoint
let g:pymode_breakpoint_bind = '<leader>b' “自動加入斷點語句
8. Code checking:
let g:pymode_lint_on_write = 1 "修改后檢查
let g:pymode_lint_checkers = ['pyflakes', 'pep8', 'mccabe'] " choose from pylint, pep8, mccabe, pep257, pyflakes
9. Rope support (建立項目文件的數據庫來索引對象):
let g:pymode_rope_ropefolder='.ropeproject' “項目文件在的目錄
let g:pymode_rope_show_doc_bind = '<C-c>d' ”查閱幫助文檔
10. Completion
語法補全命令:<C-P>/<C-N>
11. Others
let g:pymode_trim_whitespaces = 1 "Trim unused white spaces on save
let g:pymode_options = 1 "Setup default python options
let g:pymode_options_max_line_length = 79 "Setup max line length
還有關於代碼重鑄以及虛擬環境的配置功能,因為沒有用到,所以就不介紹了。 雖然配置很多,需要在vimrc中用到的也就一下幾項:
423 " For python-mode 424 let g:pymode_rope_goto_definition_bind = "<C-]>" 425 let g:pymode_python = 'python' "or python3, disable 426 "let g:pymode_virtualenv_path = $VIRTUAL_ENV 427 let g:pymode_lint_on_write = 1 428 "let g:pymode_rope_goto_definition_cmd = 'new'"or vnew
最后總結一下命令使用
1).K :查閱對象文檔
2).<leader>r: 運行python腳本
3). <leader>b:自動加入斷點
4). <C-P>/<C-N>:自動補全
5). <C-]>: 跳轉到函數定義