0

I'm new to Vim and would like to know is there a plugin, which allows you to call Python help() function on the word under cursor and shows returned text in the splitter buffer?

  • 1
    If there is not currently such a plugin (which you can google), it might not be too painful to adapt the Man plugin into something using python’s help. I’ll take a look at some point – D. Ben Knoble Nov 12 '17 at 17:01
  • Take a look at e.g. pydoc for vim--it's pretty highly rated/used on vimscripts.org. Not tried it myself – D. Ben Knoble Nov 12 '17 at 18:28
1

If you are also looking for other python features (or don't mind disabling features you don't want to have) I can recommend jedi-vim. Its main feature is autocompletion, but it has some other features like show help (K), show usages, rename and goto following imports. If you use something like youcompleteme you probably already use the jedi library for python autocompletion (and if you want to use the other jedi-vim features together with YCM you should deactivate the jedi-vim autocompletion).

I never really used default K for python files, but a single short test seems to indicate that jedi-vim K can show docs for stuff where default-vim K fails.

  • The cases in which the default K will fail (and how jedi-vim handles them) are described in this earlier, more specific, question. – Rich Nov 13 '17 at 14:24
  • I'm using completor.vim with the Jedi and it does a great job providing docs right when you type a the function. I just tried to install Jedi as a plugin and it does exactly what I asked for, thank you! – gasabr Nov 13 '17 at 20:22
  • @gasabr You may need to deactivate jedi-vim completion in that case, it could happen that both "battle each other" who completes you. But if it works it works, of course. – syntonym Nov 13 '17 at 22:05
2

It is built-in, have a look at :h K, it says

K           Run a program to lookup the keyword under the
            cursor.  The name of the program is given with the
            'keywordprg' (kp) option (default is "man").  The
            keyword is formed of letters, numbers and the
            characters in 'iskeyword'.  The keyword under or
            right of the cursor is used.  The same can be done
            with the command
                :!{program} {keyword}

On my setup keywordprg is set to pydoc automatically and thus hitting shiftk will show the pydoc entry for the current word (of course you need pydoc installed but I think it comes with the python package).

If you need something else you can simply install your prefered help program and set keywordprg accordingly without having to install a plugin.

  • wow, that's amazing! Thank you for an answer. I played with K for a bit, and noticed that it can only look up into standard library, but not in the imported packages. I tried to get the docs in the cl: python -c "import simpy; help(simpy.Resource)" -- it works, but is there a package which would be able to do that with import ... as ... etc? – gasabr Nov 13 '17 at 10:43
  • @gasabr It seems that the pydoc for vim plugin linked by David does this substitution so you can either try to use that or make a wrapper that you'll define as keywordprg – statox Nov 13 '17 at 10:50
0
  1. Ipython is much better suited for showing documentation. If you do "object"? it will show the documentation and if you do object?? it will pull up the source code

  2. The above suggestions regarding Jedi, Youcompleteme is very good. As far as I know you can even go to their function defintions directly if you have carefully mapped keys to certain go to functions

  3. A third library that I know encapsulates all and a lot more is python-mode. Try it out.. its ways simpler to install and run that a lot of heavier plugins. https://github.com/python-mode/python-mode

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.