Integrate Perldoc with VIM

Ovid on 2008-01-23T15:41:40

If you're primarily a Perl hacker and don't use C much, you might find it annoying when you hit 'K' in command mode. That's because VIM runs something like this:

nmap K :Map 

I've just added the following to my .vimrc:

noremap K :!perldoc   perldoc -f 

Now when you type 'K' in command mode, it will call up the appropriate perldoc, if possible.

I really should have added that to Perl Hacks. Damn.


Sweet!

stu42j on 2008-01-23T16:20:45

Hey, that's pretty sweet. Going in my .vimrc.

Perl specific remapping

baest on 2008-01-23T16:35:05

If filetype plugin is turned on this also works:

autocmd FileType perl :noremap K :!perldoc <cword> <bar><bar> perldoc -f <cword><cr>

And then K should still work as it did before when working with non-perl sources

Re:Perl specific remapping

Ovid on 2008-01-23T16:47:32

Nice point! I do have the filetype plugin enabled. Thanks :)

perl-support.vim

sigzero on 2008-01-23T17:26:11

I tend to use the plugin in the subject. It has that integrated (\rp) as well as a lot of other things.

http://vim.sourceforge.net/scripts/script.php?script_id=556

The canonical way to do this

Aristotle on 2008-01-24T11:43:52

autocmd FileType perl setlocal keywordprg=perldoc

If the perldoc -f || perldoc behaviour matters, the preferrable way to do it is to plug a shell script that works that way into keywordprg, which offers the bonus that you will have it available on the shell as well. If you really must, though, you can do it as a less than pretty one-liner:

autocmd FileType perl setlocal keywordprg=sh\ -c\ 'perldoc\ -f\ \$1\ \|\|\ perldoc\ \$1'\ --

collecting such tricks?

gabor on 2008-01-25T07:57:14

I wish there was a wiki with lots of tricks for the vi user Perl developers:

As a start I added this one to the perl5 wiki on TPF

what about module name

raptor on 2008-01-31T21:26:20

is there a way to use something else instead of "cword", so that this work on modules i.e.

Ala::Bala

(two colons)

Re:what about module name

Aristotle on 2008-02-01T11:08:15

autocmd FileType perl setlocal iskeyword+=:

Then vim will consider colons word characters for the purposes of cword.

Re:what about module name

Ovid on 2008-02-01T11:59:03

Oh, I have something analogous to that embedded in my vim stuff. I stole that trick from Damian.

Re:what about module name

raptor on 2008-02-01T20:20:37

nice, thank you