Good bye python-mode

1431173700000 » Tagged as: vim , python , pydev

I recently switched from pydev to vim for all python work. But after struggling with a nasty bug in my code for nearly two hours I was beginning to have second thoughts and started eclipse/pydev, ran it through the debugger. After that It took just 3 minutes to fix the bug including eclipse start up time. Ok, maybe it's because I haven't had any luck setting up a python debugger for vim. Maybe I should have just used pdb. Your devtools are support to make things easier not harder.

Debugging isn't the only issue, django auto complete still doesn't work with either jedi or rope. I've tried about a dozen remedies listed on various places including stackoverflow with no luck at all. It's tempting to make the swith back to pydev a permanent one,  but I am going to give it one more shot. The crux of the problem maybe with python-mode. Python-mode has a lot of other plugins under the hood and they are all sealed into small black boxes. It's just like driving a modern car. You are never really sure who is the boss.

Now I am going to uninstall python-mode, follow the outdated guide at sontek and have another go at it. Hopefully at the end of the day, I might have a working vim setup and a modernized version of the sontek guide! This is just an as it happened commentary. After I settle in I will create a howto which will hopefully be helpfull to someone else.

A couple of changes to the plugins. Instead of pyflakes I am installing syntastic and not going to install ack either. Both of these items might return to the menu  if I find that vim's search features don't meet expectations. The same goes for gundo, which seems like a nice plugin, but can it replace git? make-green and pytest are to other plugins to miss out. The sontek blog gives a link to the NERD Tree plugin is given as vim-scripts/The-NERD-tree while there is a better maintained version at 'scrooloose/nerdtree' by the same guy who bring you syntastic.

That's not the only plugins where the upto date version different from the location given in that blog post; others included ropevime (correct loctaion: python-rope/ropevim) and minibufexpl (correct as fholgado/minibufexpl.vim). All these plugins were installed using Vundle which probably wasn't around at the time the post was written. Vundle adding and removing plugins becomes completely painless. 


Now to start up. Predictably there is an error:

Error detected while processing function LoadRope:
line    4:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named ropevim
Error detected while processing /home/raditha/.vim/bundle/TaskList.vim/plugin/tasklist.vim:
line  369:
E227: mapping already exists for \t
Press ENTER or type command to continue

pip install rope ropevim takes care of the first one while for the second you will need to create a separate mapping according to your taste in keystrokes! Now the key to the whole puzzle: 

" 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>

This is something I discovered stackoverflow, with it autocomplete suddenly starts working pretty much like it does in pydev. So does auto import. Start typing and press Ctrl-Space to activate autocomplete, once the autocomplete is done do ::RopeAutoImport to have the import statement automatically added towards the top of the file. This is rather clunky and the default keymapping C-c r a c is worse! but you are free to map it to any key of your choosing and I am selecting Ctrl-F1

And that brings an abrubt end to the proceedings but I will be back soon.

The photo is a public domain pic by openclips

comments powered by Disqus