Python autocompletion on object instances in VIM


Question

I have found a strange behavior in VIM when I attempt to use autocompletion on objects:

If I instantiate the objects on a module level, the VIM autocompletion will work on the instance I create:

working completion

If I try the same when in a function or class it is not longer working:

non working completion

Does anyone know how to fix this, or is there no way to get omnicompletion working on instances in a non module-scope?

1
17
7/17/2011 3:25:01 PM

Accepted Answer

Even though it does not use Vim's omnicompletion plugin, by using rope, ropemode and ropevim it is possible to get autocompletion in methods:

enter image description here

Even though not really exactly what I wanted it works pretty well.

I got it working like this: I installed the ropevim distribution from here and added the following lines to my .vimrc file:

" Rope AutoComplete
let ropevim_vim_completion = 1
let ropevim_extended_complete = 1
let g:ropevim_autoimport_modules = ["os.*","traceback","django.*", "xml.etree"]
imap <c-space> <C-R>=RopeCodeAssistInsertMode()<CR>

Now pressing Ctrl+Space will bring up the rope completion menu.

14
7/20/2011 5:00:56 PM

I had to use the following line to get ctrl+space working

imap <Nul> <C-R>=RopeCodeAssistInsertMode()<CR>

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon