/usr/share

Dabblings in the webs and suchlike.

Posts tagged vim

Jun 9

Apr 27

Vim Python Complete Function

I finally found a nice complete function setup for python in vim. It’s simply using rope-vim’s code assistance but there are a few settings you need to enable. I should note that I was clued in on rope and a ton of other great plugins through a nice article by John Anderson on using vim as a python ide. You can follow his setup or I use janus so I dropped them into my janus folder as git submodules. The rope-vim plugin he suggests includes all the rope packages so you don’t need to install them yourself.

In the code assist section of :h ropevim.txt, you’ll see that you can set a few globals to have rope-vim handle completion:

let g:ropevim_vim_completion=1
let g:ropevim_extended_complete=1

The first setting makes the RopeCodeAssistInsertMode function behave like a vim complete function, i.e. it display a popup menu when called. And the second adds useful bits of info to each completion: the location the completion came from {'L': 'local', 'G': 'global', 'B': 'builtin', '': 'no scope available'}, it’s type, and the first line of the doc string. It’s pretty sweet!

Other than that, you might want to remap the awkward default code assist mapping of alt+shift+comma (see the filetype commands of my vimrc for an option). Also, if you’ve never used rope before it will ask you to create or open a project each time. This stores a hidden ropeproject directory that caches info about your modules to make completions faster. It’s slightly annoying to open each time but it’s worth it for completions.

And that’s all there is to it!

vim python completion menu