Vim Python 补全
我在 Vim 和 Python 补全方面遇到问题。 事实上,我完全困惑这是如何工作的。
我有通用的 gvim 7.3,在 Windows 7 上(使用 python/dyn) 我正在使用 SuperTab 插件等,其中一些 是特定于 python 的,在 vimrc 中具有以下设置:
au FileType python set omnifunc=pythoncomplete#Complete
let g:SuperTabDefaultCompletionType = "context"
let g:SuperTabContextDefaultCompletionType = "<c-n>"
我没有设置 PYTHONPATH 环境变量。
对于系统模块来说,完成工作正常。
起初我认为它对于非系统根本不起作用 代码,但事实并非如此。 下面的代码最好地显示了发生的情况:
import numpy.random # if this line is commented completion in last line works
class C(object):
def __init__(self, x_):
self.x=x_
def getX(self):
return self.x
def pr(self):
print 'ok'
a=C(10) # nothing changes if I put C() instead, even though it would be wrong
a. # here is completion in question
问题是,如果导入行被注释,则补全工作正常(a.
Python 完成的先决条件是什么? 发生了什么以及我应该做什么才能完成 Python 工作。
由于我(相对)对 Vim 很陌生,因此我们将不胜感激。
编辑: 问题似乎出在导入中使用 ab 形式。如果我执行 from numpy import random,一切都会好的。如果这个问题很容易解决,我也想让 ab 继续工作。但现在我知道了如何解决这个问题,这并不那么重要。
是否还有更多像这样的不寻常问题,以便我知道将来会发生什么?
I'm having trouble with Vim and Python completion.
In fact I'm totally confused how does this work.
I have generic gvim 7.3, on windows 7 (with python/dyn)
I'm using SuperTab plugin, amongst many others, some of which
are python-specific, with following settings in vimrc:
au FileType python set omnifunc=pythoncomplete#Complete
let g:SuperTabDefaultCompletionType = "context"
let g:SuperTabContextDefaultCompletionType = "<c-n>"
I did not set PYTHONPATH enviroment varariable.
Completion works ok for system modules.
At first I thought that it isn't working at all for non-system
code, but that's not the case.
What is happening is best shown on following code:
import numpy.random # if this line is commented completion in last line works
class C(object):
def __init__(self, x_):
self.x=x_
def getX(self):
return self.x
def pr(self):
print 'ok'
a=C(10) # nothing changes if I put C() instead, even though it would be wrong
a. # here is completion in question
Problem is that completion works (a.<tab> suggests getX and pr) if import line is commented. But it there is import numpy.random, completion brakes down.
Note: this import works normally when I run the code.
What are prerequisites for Python completion?
What's happening and what should I do to get completion working for Python.
As I am (relatively) new to Vim, any suggestion is appreciated.
EDIT:
It seems that the problem is in using a.b form in import. If I do from numpy import random, everything is ok. If this is reasonably easy to fix I would like to get a.b from to work too. But now that I know how to go around it that's not so important.
Are there more unusual problem like this one so that I know what's happening in the future?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
pythoncomplete 相当旧且无人维护。
尝试使用 Jedi:https://github.com/davidhalter/jedi-vim
它最初是一个改进的 pythoncomplete,但现在更强大了!
它适用于复杂的代码:
并具有附加功能:
有一个所有可能功能的列表:
__call__
、__iter__
、__next__
、__get__
、__getitem__
、__init__
getattr()
/__getattr__
/__getattribute__
我不知道如何处理它们。)
情况下,这不适用于 Jedi)
sys.path
修改isinstance
检查 if/while/assertpythoncomplete is rather old and unmaintained.
Try to use Jedi: https://github.com/davidhalter/jedi-vim
It was originally an improved pythoncomplete, but is now much much more powerful!
It works for complex code:
And has additional features:
There is a list of all possible features:
__call__
,__iter__
,__next__
,__get__
,__getitem__
,__init__
getattr()
/__getattr__
/__getattribute__
I don't know what to do with them.)
case, that doesn't work with Jedi)
sys.path
modificationsisinstance
checks for if/while/assertPython 作为一种极其动态的语言,并不适合自己完成。那里没有任何真正好的完成度。在我看来,没有它生活比与它的所有问题作斗争更容易。也就是说,python-mode 确实很棒,就像 Neoascetic 所说的那样。
Python, being an incredibly dynamic language, doesn't lend itself to completion. There isn't any really good completion out there. It's easier to just live without it than to fight with all its problems, IMO. That said, python-mode really is fantastic, like neoascetic said.