Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何为非标准Python库向Vim添加自动完成?_Python_Vim_Autocomplete - Fatal编程技术网

如何为非标准Python库向Vim添加自动完成?

如何为非标准Python库向Vim添加自动完成?,python,vim,autocomplete,Python,Vim,Autocomplete,例如,我有一个使用Google App Engine SDK的Python脚本: from google.appengine.ext import db from google.appengine.ext import webapp from google.appengine.ext.webapp import template from google.appengine.ext.webapp.util import run_wsgi_app 模块db有一个子模块键,因此我尝试在其上使用aut

例如,我有一个使用Google App Engine SDK的Python脚本:

from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
模块
db
有一个子模块
,因此我尝试在其上使用autocomplete:

db.K
Tab

但在Vim窗口的底部,我得到以下信息:

-- Omni completion (^O^N^P) Pattern not found

如何包含非标准Python库的路径,以便Vim autocompletion可以找到它们?并显示其文档字符串?

您需要将库文件添加到标记文件中。例如,如果您通过pip在位于env/的虚拟环境中安装了Google App Engine:

virtualenv --no-site-package env/
source env/bin/activate
pip install google_appengine
。。。然后您应该执行:

ctags -R --python-kinds=-i -o tags env/
如果您没有通过pip安装google_appengine,那么您应该找到python库的路径(提示:它应该由$PYTHONPATH.指示,根据参考页:“在Unix上,这通常是.:/usr/local/lib/python.”),并用找到的路径替换env/

最后,您的.vimrc文件应该解析您的标记文件。例如,在my.vimrc中,我有:

set tags+=/path/to/my/tags

我从natw的vimrc(我想……也许是sontek)那里得到了这个,但它应该可以做到这一点,只要您的包可以通过当前安装的Python找到。这使您可以使用gf,但也可以设置搜索这些文件的自动完成。注意
py如果我没有使用
pip
,该怎么办?比如说,做点类似指向图书馆的路径的事情?这是什么程序?
function! LoadPythonPath() 
py <<EOF
    # load PYTHONPATH into vim, this lets you hover over a module name
    # and type 'gf' (for goto file) and open that file in vim. Useful
    # and easier than rope for simple tasks 
    import os.path 
    import sys 
    import vim 
    for p in sys.path:
        if os.path.isdir(p):
            vim.command(r"set path+=%s" % (p.replace(" ", r"\ "))) 
EOF

    endfunction
function! GetPythonPath()
    if !exists("g:PythonPathLoaded")
        call LoadPythonPath()
        return
    elseif g:PythonPathLoaded
        return
    else
        call LoadPythonPath()
    endif
endfunction
function! UnloadPythonPath()

py <<EOF
    # load PYTHONPATH into vim, this lets you hover over a module name
    # and type 'gf' (for goto file) and open that file in vim. Useful
    # and easier than rope for simple tasks
for p in sys.path:
    if os.path.isdir(p):
        vim.command(r"set path-=%s" % (p.replace(" ", r"\ ")))
EOF

    let g:PythonPathLoaded = 0
endfunction