This tip presents several ways to access Python documentation using pydoc. The recommended location for the commands in this snippet is ~/.vim/after/ftplugin/python.vim, or $HOME\vimfiles\after\ftplugin\python.vim on Windows.

Using the preview window or a scratch buffer

This snippet allows you to use the command :Pyhelp <string> to preview Python documentation in the preview window. It also remaps K in the same manner as above.

If Vim is compiled with +python, it automatically finds the path to pydoc.py. Otherwise, set the s:pydoc_path variable to a suitable value. This seemingly indirect approach is used in an effort to make the snippet platform agnostic.

See also

References

Comments

For an alternative approach to the same problem, try the pyref.vim plug-in (
script#3104) which provides context-sensitive documentation for Python source code by looking up help topics on docs.python.org (or a local mirror on your file system) and showing them in your favorite web browser.