Vim,Python和Django自动完成(pysmell?)(Vim, Python, and Django autocompletion (pysmell?))

编程入门 行业动态 更新时间:2024-10-26 00:23:24
Vim,Python和Django自动完成(pysmell?)(Vim, Python, and Django autocompletion (pysmell?))

有没有人知道如何使用python,django和vim来完成自动完成工作?

我一直在尝试使用pysmell,但我似乎无法正确设置它(或者也许我不知道它是如何工作的)。 现在,我在django目录中运行pysmell(我正在使用中继线),并将生成的标签移动到我的项目目录,然后我也在项目目录中运行pysmell。 不过Vim并没有拿起django标签,而是没有自动完成。

有没有人知道如何在vim中设置自动完成,以便它可以在我自己的代码中完成长django函数(如get_object_or_404)以及类/函数。 我在google上戳了一下,但没有找到任何好的资源。

谢谢。

Does anyone know how to set up auto completion to work nicely with python, django, and vim?

I've been trying to use pysmell, but I can't seem to get it set up correctly (or maybe I don't know how it works). Right now, I run pysmell in the django directory (I'm using the trunk) and move the resulting tags to my project directory, then I also run pysmell in the project directory. Vim doesn't pick up the django tags, though, and they don't get auto completed.

Does anyone know how to set up auto completion in vim so that it will complete the long django functions (like get_object_or_404) as well as classes/functions in my own code? I have poked around on google but haven't found any good resources.

Thanks.

最满意答案

首先,谢谢你提出这个问题,因为它强迫我自己弄清楚,这是伟大的!

这是我用作参考的页面: PySmell v0.6发布:orestis.gr

使用setup.py install命令安装PySmell。 通过访问您的site-packages/django目录并运行: pysmell . -o ~/PYSMELLTAGS.django生成django的PYSMELLTAGS文件pysmell . -o ~/PYSMELLTAGS.django pysmell . -o ~/PYSMELLTAGS.django 将该文件复制到您的项目目录,然后运行pysmell . 生成项目PYSMELLTAGS文件 确保pysmell在您的PYTHONPATH ( export PYTHONPATH=${PYTHONPATH}:/path/to/pysmell/ ) 运行vim( vim . ) 来源pysmell.vim ( :source /path/to/pysmell/pysmell.vim ) 设置自动完成命令( :set omnifunc=pysmell#Complete ) 键入^ x ^ o自动完成,它应该工作

我意识到这不是一个可持续的解决方案,但是您应该可以使用它作为开始,使其设置始终工作(例如,将导出添加到.bashrc中,将源代码添加到.vimrc,setup autocmd FileType python set omnifunc=pysmell#Complete等)

让我知道这是否足以让你开始。 它为我工作!

编辑我只是将它添加到我的.vimrc,只要PYSMELLTAGS和PYSMELLTAGS.django文件在我的项目根目录,它可以正常工作没有任何其他工作:

python << EOF import os import sys import vim sys.path.append("/usr/local/python/lib/python2.5/site-packages") EOF exe ":source ~/src/pysmell/pysmell.vim" autocmd FileType python set omnifunc=pysmell#Complete

First off, thank you for asking this question, as it forced me to figure this out myself and it's great!

Here is the page I used as a reference: PySmell v0.6 released : orestis.gr

Install PySmell using the setup.py install command. Generate the PYSMELLTAGS file for django by going to your site-packages/django directory and running: pysmell . -o ~/PYSMELLTAGS.django Copy that file to your project directory, and then ran pysmell . to generate the project PYSMELLTAGS file Make sure pysmell is in your PYTHONPATH (export PYTHONPATH=${PYTHONPATH}:/path/to/pysmell/) Run vim (vim .) Source pysmell.vim (:source /path/to/pysmell/pysmell.vim) Set the autocomplete command (:set omnifunc=pysmell#Complete) Type ^x^o to autocomplete and it should work

I realize this is not a sustainable solution, but you should be able to use this as a start to getting it setup to always work (e.g., add the export to your .bashrc, add the :source to your .vimrc, setup autocmd FileType python set omnifunc=pysmell#Complete, etc.)

Let me know if this is enough to get you started. It worked for me!

Edit I simply added this to my .vimrc and as long as the PYSMELLTAGS & PYSMELLTAGS.django files are in my project root, it works fine without any other work:

python << EOF import os import sys import vim sys.path.append("/usr/local/python/lib/python2.5/site-packages") EOF exe ":source ~/src/pysmell/pysmell.vim" autocmd FileType python set omnifunc=pysmell#Complete

更多推荐

本文发布于:2023-08-05 14:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1433993.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自动完成   Python   Vim   Django   autocompletion

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!