Two-Bit Alchemist
Two-Bit Alchemist

Reputation: 18477

Locate the Containing Package or Module **Before** Importing

I often find myself needing to import something, but not quite sure of its fully qualified name. I usually end up opening a browser, performing an internet search like python [target_of_import], and scanning a page or two until I find it.

This works, but causes a relatively long break in my workflow, especially if I have to search for a few in a row. How do other people address this?

Is there something like Haskell's Hoogle for Python?

[Note: I currently use vim, in case anyone suggests an IDE-based solution.]

EDIT: For answers concerning autocomplete, please specify this. In general, autocomplete is probably a non-starter solution since in the particular case I am asking about the leftmost characters of the string to be autocompleted are not known.

EDIT 2: While I will not categorically rule out suggestions concerning switching to/learning a new IDE, I'm pretty unlikely to completely change the way I work to accomplish this (e.g., switching from vim on the command line to something like Eclipse + plugins).

Upvotes: 4

Views: 122

Answers (1)

Brett Y
Brett Y

Reputation: 7688

You can do this in vim using the Unite.vim

Enable fuzzy file searching by adding the following to your .vimrc:

call unite#filters#matcher_default#use(['matcher_fuzzy'])

Search for file:

:UniteWithInput file_rec/async:/base/path:!<cr>

Search within files:

:UniteWithInut grep:/base/path<cr>

Search file names and within files

:UniteWithInput file_rec/async:/base/path:! grep:/base/path<cr>

(Use to change between sources)

See also :h :UniteWithCursorWord

This will open a buffer with the file matches. You can open the file by pressing enter but since you only want copy the file name simply use y$ to yank the line, q to close the buffer and the p to paste the yanked line.

Upvotes: 1

Related Questions