Technology
 

Get help on Python libraries

From Vim Tips Wiki

(Redirected from VimTip867)

Obsolete tip

This tip has been merged into another tip.
See VimTip556 for the current tip.

Please do not edit this tip, and do not edit the discussion page.
If anything needs to be improved, please fix VimTip556.


Tip 867 Previous Next created 2005 · complexity basic · version 7.0


This snippet allows you to run :Pyhelp <module> to preview pydoc documentation in the preview window.

It requires pydoc.py, which comes with most Python installations.

If Vim is compiled with +python, it automatically finds the path to pydoc.py. Otherwise, set the g:pydoc_path variable to a suitable value.

if has("python")
" let python figure out the path to pydoc
python << EOF
import sys
import vim
vim.command("let g:pydoc_path=\'" + sys.prefix + "/lib/pydoc.py\'")
EOF
else
  " manually set the path to pydoc
  let g:pydoc_path = "/path/to/python/lib/pydoc.py"
endif

command! -nargs=1 Pyhelp :call ShowPydoc(<f-args>)
function! ShowPydoc(module)
  " compose a tempfile path using the module name
  let path = $TEMP . '/' . a:module . '.pydoc'
  " run pydoc on the module, and redirect the output to the tempfile
  call system(shellescape(g:pydoc_path . " " . a:module . " > " . path))
  " open the tempfile in the preview window
  execute ":pedit " . path
endfunction

See also script#910 and script#1112.

[edit] Comments

I believe that this snippet is platform agnostic. Please correct it if you find any problems. (Spiiph 17:35, 28 January 2009 (UTC))