views:

106

answers:

1

In eclipse, there is this handy shorthand CTRL+SHIFT+o which will auto include the import (include) statements which are needed based on the Class or module being used. Have you found any such plugin for vim or emacs?

A: 

Ropemacs has rope-auto-import, so that if you write

rmtree

and execute M-x rope-auto-import,

from shutil import rmtree

is inserted at the top of the file. You might want to avoid this though, because importing functions from modules may not be a very wise idea.

See this SO post for information on setting up ropemacs. The README (e.g. /usr/share/doc/python-ropemacs/README.txt.gz) that comes with ropemacs also has useful information for setting up the cache used by the ropemacs-auto-import command.

unutbu
unutbu, that's an useful pointer. BTW, can't ropemacs do a non-relative import. As in, I use shutil.rmtree and when I do M-x ropemacs-auto-import, it does import shutil ?
Senthil Kumaran
@Senthil: Unfortunately, AFAIK, `M-x rope-auto-import` can only create imports of the "from X import Y" variety.
unutbu