Friday, August 15, 2008

Making K Useful

The default behavior of the K command is to lookup the keyword under the cursor using man. This is handy at times, but it's not very useful when I spend 90% of my day writing PHP code. Vim's online help mentions that you can set keywordprg to an alternative program, so I did the following.

set keywordprg=/home/travis/pdoc

Where pdoc is the following shell script:

 #!/bin/sh
firefox http://us3.php.net/manual/en/function.$1.php

Now I can move the cursor over a builtin function, hit K, and firefox will open to the appropriate documentation. To keep things strictly textual, you could use lynx (or links) in lieu of firefox.

For ruby code, I like to do the following:

set keywordprg=ri

For Perl:

set keywordprg=perldoc\ -tf

3 comments:

Robert Webb said...

I found a way to do this for Windows, inspired by your tip. Just put the following in a file called $VIM\vimfiles\ftplugin\php_help.vim

Doh! It won't let me post it because it thinks it's HTML, and I can't see any option to quote it. OK, you can download the file from here instead:

http://www.software3d.com/php_help.vim

I did it via a mapping without any reference to an external batch file.

Rob.

Andrew said...

Nice. I just started working with perl again, and this is perfect for trying to remember what stuff does.

Travis Whitton said...

Very cool Rob. Thanks for the contribution!