Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix absent Python autocompletion on object instances in Vim?

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:

Screenshot of working completion

If I try the same from within a function or class, it is no longer working:

Screnshot of non-working completion

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

like image 912
BergmannF Avatar asked Jul 17 '11 14:07

BergmannF


2 Answers

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

Autocompletion screenshot

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

I got it working like so: 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.

like image 186
BergmannF Avatar answered Nov 11 '22 05:11

BergmannF


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

imap <Nul> <C-R>=RopeCodeAssistInsertMode()<CR>
like image 31
Oliver Avatar answered Nov 11 '22 06:11

Oliver