# Open a Perl module from its module name

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 module

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>

execute 'e perldoc -l ' . expand("<cWORD>") . ''
endfunction


## View perldoc information

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.

TO DO

• 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)