交互模式下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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值