61

I am trying to incorporate an autocomplete feature in Vim. I have used the omnicompletion of Vim as well as Pydiction. But in both the cases this message pops up:

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

I have tried Vim's Omnicompletion with Python just doesn't work. But this is not helping. Is there a workaround?

Community
  • 1
  • 1
tallandroid
  • 726
  • 1
  • 7
  • 8
  • 2
    did you see this link ? http://blog.dispatched.ch/2009/05/24/vim-as-python-ide/ – Mohammad Efazati Aug 21 '11 at 11:47
  • 1
    Is the file detected as a python file? Open it up and run `:echo &ft`. If this doesn't return "python" then try adding 'filetype plugin on' to your vimrc and try all this again. – Randy Morris Aug 21 '11 at 12:22
  • Old question: [Getting proper code completion for Python on Vim? - Stack Overflow](https://stackoverflow.com/questions/1520576/getting-proper-code-completion-for-python-on-vim) with some (older) plugins. — ■ Not really answer this *particular* question, but if you're already using `jupyter-vim`, check out my package `jupyter-vim-complete` which does completion based on the runtime state of the kernel. – user202729 Dec 11 '21 at 06:09

7 Answers7

74

Try Jedi! There's a Vim plugin at https://github.com/davidhalter/jedi-vim.

It works just much better than anything else for Python in Vim. It even has support for renaming, goto, etc. The best part is probably that it really tries to understand your code (decorators, generators, etc. Just look at the feature list).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dave Halter
  • 15,556
  • 13
  • 76
  • 103
17

As pointed out by in the comments, this answers is outdated. youcompleteme now supports python3 and jedi-vim no longer breaks the undo history.

Original answer below.


AFAIK there are three options, each with its disadvantages:

  1. youcompleteme: unfriendly to install, but works nice if you manage to get it working. However python3 is not supported.
  2. jedi-vim: coolest name, but breaks your undo history.
  3. python-mode does a lot more the autocomplete: folding, syntax checking, highlighting. Personally I prefer scripts that do 1 thing well, as they are easier to manage (and replace). Differently from the two other options, it uses rope instead of jedi for autocompletion.

Python 3 and undo history (gundo!) are a must for me, so options 1 and 2 are out.

Rafael Barbosa
  • 1,120
  • 12
  • 17
  • 2
    Thanks for pointing out the downsides, that made the choice much easier, since I share the opinion about Python 3 and undo. – Zelphir Kaltstahl Oct 22 '16 at 17:07
  • It seems that rope doesn't support Python 3 (https://github.com/python-rope/rope/issues/57)? How to use the autocomplete function with python-mode and rope? Thanks. – Leo Jan 17 '18 at 11:10
  • 6
    This is not accurate anymore. YouCompleteMe now supports Python 3. – jimh Mar 02 '20 at 18:06
  • also, jedi-vim doesn't break undo anymore (at least not in vim 8+) – beep_check Jun 24 '20 at 03:15
14

This can be a good option if you want python completion as well as other languages. https://github.com/Valloric/YouCompleteMe

The python completion is jedi based same as jedi-vim.

Xuan
  • 5,255
  • 1
  • 34
  • 30
7

I tried pydiction (didn't work for me) and the normal omnicompletion (too limited). I looked into Jedi as suggested but found it too complex to set up. I found python-mode, which in the end satisfied my needs. Thanks @klen.

Community
  • 1
  • 1
Torsten Engelbrecht
  • 13,318
  • 4
  • 46
  • 48
  • This is the one that worked for me. The other tools were too complicated to install. – max Apr 08 '15 at 19:49
2

I found a good choice to be coc.nvim with the python language server.

It takes a bit of effort to set up. I got frustrated with jedi-vim, because it would always freeze vim for a bit when completing. coc.nvim doesn't do it because it's asyncronous, meaning that . It also gives you linting for your code. It supports many other languages and is highly configurable.

The python language server uses jedi so you get the same completion as you would get from jedi.

ak17
  • 167
  • 1
  • 9
2

Use install coc.nvim package and CocInstall coc-pyright

if you are using vim-plug:

  1. Plug 'neoclide/coc.nvim'
  2. :PlugInstall
  3. CocInstall coc-pyright
fannheyward
  • 18,599
  • 12
  • 71
  • 109
Orif Milod
  • 465
  • 1
  • 7
  • 17
0

I ran into this on my Mac using the MacPorts vim with +python. Problem was that the MacPorts vim will only bind to python 2.5 with +python, while my extensions were installed under python 2.7. Installing the extensions using pip-2.5 solved it.

Devon Bleak
  • 244
  • 3
  • 4