星期五, 2月 19, 2010

用Vim開發Python

找了一下網路上文件,一共會有些plugin需要使用。
1.minibufexpl.vim
可以開多個檔案的時候會有tab出現,需要切換的話control+ww然後移到要切換的tab上即可,
或是用滑鼠點要切換的tab也可以。

2.taglist.vim
可以出現檔案中的函式,member等的樹狀結構。
安裝此plugin需要ctags,所以就先

$http://vim.sourceforge.net/scripts/script.php?script_id=273

再下載下來安裝。解壓縮後會有兩個檔案,一個是doc,另外一個是plugin。
plugin就放在$HOME/.vim/plugin/裏面,再把doc放到$HOME/.vim/doc裏面,
在此目錄下執行vim以後,輸入

:helptags .

如此以後才可以有help查。
接著就可以使用taglist了!要使用只要輸入:TlistToggle就可以切換出視窗了。

3.VimPdb
可以直接在Vim裏面debug囉。抓下來後把VimPdb.vim & VimPdb.py直接放到.vim/plugin資料夾中即可。
如果不行
a.先檢查Vim是否支援Python
:python print "hellp world"
看是否有錯誤訊息
b.如果出現如下錯誤訊息

Error message:

Error detected while processing /home/user/.vim/plugin/VimPdb.vim:
line 19:
E492: Not an editor command: import sys
line 20:
E319: Sorry, the command is not available in this version: python
sys.path.insert(0, r"/home/user/.vim/plugin")
line 21:
E492: Not an editor command: import VimPdb
Error detected while processing function PdbInitialize:
line 11:
E319: Sorry, the command is not available in this version: ^Ipython import sys
line 12:
E319: Sorry, the command is not available in this version: python
sys.path.insert(0, r"")
line 13:
E319: Sorry, the command is not available in this version: ^Ipython import
VimPdb
line 15:
.....省略

應該是vimpdb.vim的檔案格式有問題,用vim打開它,然後輸入

:set fileformat=unix
:w

就可以正常運作了。

4.pythoncomplete
怎麼可以少了autocomplete呢!
下載下來放在plugin資料夾後,需要autocomplete時,再按Ctrl+x Control+o就可以了,還有文件說明,好厲害!

5.自動縮排
vim能自動偵測*.py後,就可以.vimrc中加上
filetype indent on
就可以自動縮排了!

沒有留言: