Vim Tips Wiki

Open a Perl module from its module name

1,624pages on
this wiki
Add New Page
Talk0 Share
Tip 461 Printable Monobook Previous Next

created 2003 · complexity basic · author Mark Stosberg · version 6.0

This tip shows some techniques for accessing information when editing a Perl program. See also Perldoc function and module keyboard mappings (which should be merged to here).

Open a Perl moduleEdit

You may want to open the source code of a system Perl module that's installed. Here's one way to do that:

:e `perldoc -l Module::Name`

The following function will allow you to set your cursor over a Perl module name in the file that you are currently editing and type \pm to open the corresponding source file in a new buffer:

nnoremap <Leader>pm :call LoadPerlModule()<CR>

function! LoadPerlModule()
  execute 'e `perldoc -l ' . expand("<cWORD>") . '`'

View perldoc informationEdit

If you use the K command in Perl files, it will try to invoke 'man' on Perl keywords/functions. But this does not make much sense. It is more useful to redirect K to use 'perldoc -f' in a Perl file. Add this to your vimrc:

au FileType perl setlocal keywordprg=perldoc\ -T\ -f

and K will lookup Perl function names using 'perlfoc -f' for you.

See alsoEdit

Online documentation for word under cursor



  • Cleanup this and VimTip614, and merge 614 to here.
  • Rename this tip.
  • I'm pretty sure all the autocmd suggestions are misguided (and should be deleted).
  • Instead, show how to use an after/ftplugin/perl.vim file.

The following have suggestions for working with K that may be helpful in this tip:

I had a quick try with the after file, but there is some weird stuff going on with iskeyword that I'd like to sort out before doing any further cleaning. JohnBeckett 05:28, 5 April 2009 (UTC)

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.