5

I tried python-mode, it seems that it can work when I press K on "numpy.array", but if I want to press K on "np.array", it won't work.

yihui.dev
  • 153
  • 4
  • 2
    That's because np is not the name of a module itself; it is a variable defined within the program to be another name for an already existing module. Therefore, you cannot find help on it without actually running the program. – zondo May 08 '16 at 01:28
  • @zondo I understand. If there's a way like vim help command, let me able to do :help(numpy.array). Or do you have some suggestions? – yihui.dev May 08 '16 at 02:39
  • 2
    You could use :!pydoc numpy.array – zondo May 08 '16 at 02:41
  • @zondo, thanks! I don't need to google usage every time. – yihui.dev May 08 '16 at 02:48
  • 1
    It's a pleasure! For more information, try :help :! from within Vim. You might also find man pydoc from the terminal to be interesting. – zondo May 08 '16 at 02:51

1 Answers1

9

Try using the jedi-vim plugin. It uses Jedi to get completions and is much better at doing so than python-rope is. It will resolve np.array to numpy.array and show the appropriate documentation in a tab/split. Be warned that numpy is notoriously slow for Jedi to resolve when it's not cached.

zondo's suggestion to use :!pydoc numpy.array does work, but I find it annoying because I can't use Vim mappings to navigate the output, yank text from it, or leave it open for reference. There's also the issue of using a virutalenv, which may not have pydoc in the virtualenv's $PATH. In that case, you would have to use: :!python -m pydoc numpy.array.

Tommy A
  • 6,770
  • 22
  • 36