交互模式下PYTHON自動補全和VIM中PYTHON自動補全


有時簡單試驗一下小代碼或某個類的方法,還是用交互模式下的python比較方便;不過有一個問題,交互模式python默認沒有自動補全功能。我用的是Mac Air上自帶的Python,由於Mac OS X的一些特殊性(詳見後面的參考文檔),網上找了一些辦法都不行,最後用瞭如下這個,很好用,按tab兩次可以提示自動補全。
1
2
3
4
5
6
import readline
import rlcompleter
if 'libedit' in readline.__doc__:
readline.parse_and_bind("bind ^I rl_complete")
else:
readline.parse_and_bind("tab: complete")
上面腳本保存爲~/.pythonstartup ,然後 echo ‘export PYTHONSTARTUP=~/.pythonstartup’ >> ~/.bash_profile 重新打開shell即可
PYTHONSTARTUP
If this is the name of a readable file, the Python commands in that file are executed before the first prompt is displayed in interactive mode. The file is executed in the same namespace where interactive commands are executed so that objects defined or imported in it can be used without qualification in the interactive session.
現在寫個python小程序,也不想用啥特別的IDE了,就用Vim也挺好的。說下vim上配置python的自動補全吧。
1.安裝Vundle,讓Vim上安裝/更新pulgin非常的方便。
2.安裝Jedi-vim用於自動補全:在~/vimrc 中添加 Plugin ‘davidhalter/jedi-vim’ 然後打開Vim在命令模式下用BundleInstall命令即可完成。
順便說一下,我還用了 Plugin ‘klen/python-mode’(安裝方法類似),它可以給我們pep8/pyflakes等檢查,同時也提供了rope的自動補全。個人覺得rope沒有jedi好用,所以還是關閉rope設置一下 let g:pymode_rope = 0 。
參考文檔:
http://stackoverflow.com/questions/7116038/python-tab-completion-mac-osx-10-7-lion/7116997
http://unlogic.co.uk/2013/02/08/vim-as-a-python-ide/
https://docs.python.org/2/using/cmdline.html#environment-variables
更多精彩文章,請搜索微信公衆號扶艾。我們定期分享OpenStack相關技術文章,在這裏,只有純乾貨。 


原文博客地址:smilejay.com
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章