Is there any way to get python omnicomplete to work with non-system modules in vim?

The only thing I can get python omnicomplete to work with are system modules. I get nothing for help with modules in my site-packages or modules that I'm currently working on.


Asked by: Fenton966 | Posted: 05-10-2021






Answer 1

Once I generated ctags for one of my site-packages, it started working for that package -- so I'm guessing that the omnicomplete function depends on ctags for non-sys modules.

EDIT: Not true at all.

Here's the problem -- poor testing on my part -- omnicomplete WAS working for parts of my project, just not most of it.

The issue was that I'm working on a django project, and in order to import django.db, you need to have an environment variable set. Since I couldn't import django.db, any class that inherited from django.db, or any module that imported a class that inherited from django.db wouldn't complete.

Answered by: Joyce577 | Posted: 06-11-2021



Answer 2

I get completion for my own modules in my PYTHONPATH or site-packages. I'm not sure what version of the pythoncomplete.vim script you're using, but you may want to make sure it's the latest.

EDIT: Here's some examples of what I'm seeing on my system...

This file (mymodule.py), I puth in a directory in PYTHONPATH, and then in site-packages. Both times I was able to get the screenshot below.

myvar = 'test'

def myfunction(foo='test'):
    pass

class MyClass(object):
    pass

Answered by: Marcus542 | Posted: 06-11-2021



Answer 3

Just ran across this on Python reddit tonight: PySmell. Looks like what you're looking for.

PySmell is a python IDE completion helper.

It tries to statically analyze Python source code, without executing it, and generates information about a project’s structure that IDE tools can use.

Answered by: Brad820 | Posted: 06-11-2021



Answer 4

While it's important to note that you must properly set your PYTHONPATH environmental variable, per the the previous answer, there is a notable bug in Vim which prevents omnicompletion from working when an import fails. As of Vim 7.2.79, this bug hasn't been fixed.

Answered by: Roland725 | Posted: 06-11-2021



Answer 5

Trouble-shooting tip: verify that the module you are trying to omni-complete can be imported by VIM. I had some syntactically correct Python that VIM didn't like:

:python import {module-name}
 Traceback (most recent call last):
   File "<string>", line 1, in ?
   File "modulename/__init__.py", line 9
     class empty_paranthesis():
                            ^
 SyntaxError: invalid syntax

Case-in-point, removing the parenthesis from my class definition allowed VIM to import the module, and subsequently OmniComplete on that module started to work.

Answered by: Max114 | Posted: 06-11-2021



Answer 6

I think your after the pydiction script. It lets you add your own stuff and site-packages to omni complete.

While your at it, add the following to your python.vim file...

 set iskeyword+=.

This will let you auto-complete package functions e.g. if you enter...

 os.path.

and then [CTRL][N], you'll get a list of the functions for os.path.

Answered by: Adrian428 | Posted: 06-11-2021



Similar questions

Problem with Vim omnicomplete and system Python

I have Vim set up, with +python (:version says it's ok). My .vimrc contains filetype plugin on set ofu=syntaxcomplete#Complete autocmd FileType python setlocal omnifunc=pythoncomplete#Complete When some .py file is open, and I type i.e. pri and press Ctrl-X, Ctrl-O, it says no patte...


python - Omnicomplete and Vim, complete functions from non-imported classes

I am using Vim for editing python (using numpy, scipy) codes with the supertab plugin. Is there a way to tell omnicomplete in ~/.vimrc that np always denotes the numpy lib (as if I typed import numpy as np at the beginning of the code) and thus force it to complete e.g. np.arr to np.array..., even if the lib is not imported in that particular code?


Can Omnicomplete in Vim for python/3 complete function names or just methods?

To illustrate my question, here is a simple example of how Omnicomplete is acting on my machine: name = "Bob" na&lt;C-x&gt;&lt;C-o&gt; gives-----&gt; name name.&lt;C-x&gt;&lt;C-o&gt; gives-----&gt; (correct dropdown menu of methods for string) prin&lt;C-x&gt;&lt;C-o&gt; gives-----&gt; (-- Omni completion (^O^N^P) Pattern not found) I was expecting the last line to expand to


In termux, how do I get vim python omnicomplete to work?

I'm using vim-python in termux. Onmicomplete completes nothing. I mean C-X, C-O does nothing. Not a single keyword, module, nothing. It always gives no pattern found. $ pkg list-installed | grep vim WARNING: apt does not have a stable CLI interface. Use with caution in scripts. vim-python/stable,now 8.1.2000 arm [installed] vim-runtime/stable,now 8.1.2000 all ...






Still can't find your answer? Check out these communities...



PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python



top