Vim's Omnicompletion with Python just doesn't work Vim's Omnicompletion with Python just doesn't work python python

Vim's Omnicompletion with Python just doesn't work


What module contains the symbol you are trying to complete? Is it in the python stdlib? Or is it a third-party module?

Make sure that the module/package is in the PYTHONPATH.

In Vim, do:

:python import sys:python print sys.path

To add the module's directory:

:python sys.path.append("/path/to/directory/")


Sounds like the questioner has long since gone to the dark side*, but for what it's worth I've just had this symptom, and in my case the cause was that a module I was using relied on Python 2.7 but my version of Vim was compiled with Python 2.5.

To diagnose I tried :python import mymodule, which failed with an error about importing a dependent module. Then :python import dependentmodule which failed with the next step in the chain. And so on & so on, until it failed trying to import a system module that was new since Python 2.7. Problem found.

To solve, I just did sudo port install vim +python27. But that's for OSX. YMMV.

(* I'm kidding. Emacs users are our friends. It's the people programming in Notepad we all have to save...)


Since you were prudent and made certain your code is reachable by the PYTHONPATH, per codeape's suggestion, is there a possibility that you are running into the import bug for Vim Python omni-complete? This bug still exists as of Vim 7.2.245.

Essentially, if any import statement fails in the file you are working in, regardless of whether it's wrapped in a Try-Except clause, it will completely break omni-completion. It should be fairly easy to check for this, since most imports occur at the very beginning of the file.

If you do decide that this bug is the cause of your troubles, your options include:

  • making sure that the modules you import are on the system path, not just the project files
  • commenting out any import statements that fail
  • fixing the bug
  • using ropevim as your completion method
  • using a different editor; Netbeans IDE has Python support, and the jVi plugin is rather good if you're a Vim addict like myself (don't let the 1990s look of the home page fool you)