PHP online help
From Vim Tips Wiki
Tip 598 Previous Next Created: October 30, 2003 Complexity: basic Author: Macel Preda Version: 5.7
While editing a .php file, I may need the php manual to see the parameters order for functions.
You might open a browser and visit http://ro.php.net/FUNCTION_NAME (for example http://ro.php.net/printf).
However, you can use:
set keywordprg=a_script
Then, by default, when the cursor is on a WORD and you press K in normal mode, Vim will run 'man WORD'. If you set keywordprg=a_script, Vim will run 'a_script WORD'.
So I have
set keywordprg=/home/marcel/php_doc
and php_doc looks like:
#!/usr/bin/bash links http://www.php.net/$1
And now I have online help.
links is a text browser for *nix, http://links.browser.org/ Of course you can use lynx.
[edit] References
[edit] Comments
How can I get back in my file after I visit the doc file?
after you get out from the browser [use q] all you have to do is:
'Hit ENTER or type command to continue' [Vim says that]
If you work in X and you use more mozilla than lynx i think you could like this script instead of other:
#!/bin/bash #php_doc mozilla=/when/you/have/mozilla if ( $mozilla -remote "ping()" &> /dev/null );then $mozilla -remote "openurl(http://www.php.net/$1, new-tab)" & else $mozilla http://www.php.net/$1 & fi
This script start mozilla if not running, and send it the new url. If you want to know the others command to use with -remote flag see here: http://www.mozilla.org/unix/remote.html
My script for opera:
#!/bin/bash /usr/bin/opera -windowname vimphphelp -newpage http://php3.de/$1
It will open all PHP documenation pages in its own window, with a new tab for each function.
php3.de works fast enough for me, change it to the closest mirror to you!
You can use the offline version of the php documentation too:
put "set keywordprg=~/.vim/php_doc.sh" in ~/.vim/ftplugin/php.vim
php_doc.sh:
#!/bin/sh FUNCTION=`echo $1 | sed 's/_/-/g'` lynx file:///home/karel/dox/manuals/phpmanual/function.$FUNCTION.html
In the php_doc script, you can use this in Mac OS X
open http://www.php.net/$1
this will open the keyword in your default browser
Here's my keywordprg script.
#!/usr/bin/sh FUNCTION=`echo $1 | sed 's/_/-/g'` links -dump http://uk.php.net/manual/en/print/function.$FUNCTION.php | sed -n -e '15p' -e '19,20p'
Here's my version: This one strips the top off section of weboutput so that the help page starts with the function definition.
#!/bin/bash #links http://www.php.net/$1 FUNCTION=`echo $1 | sed 's/_/-/g'` links -dump http://uk.php.net/manual/en/print/function.$FUNCTION.php | tr -d '\r' | perl -ne "if (/---------------/) {\$f=1;} if (\$f==1) { print; }"
I created this file to return back just the description line. Feel free to edit/alter. It works for me, and I am even more happier with Vim.
#!/bin/bash FUNCTION=`echo $1 | sed 's/_/-/g'` links -dump http://www.php.net/manual/en/print/function.$FUNCTION.php | grep -A 5 Description | grep $1
This will give the function reference up to the User Contributed Notes and will only alter keywordprg for php files:
~/.vim/php_doc:
#!/bin/bash FN=`echo $1 | sed 's/_/-/g'` echo '**********************' lynx -dump -nolist http://www.php.net/manual/en/print/function.$FN.php | sed -n /^$1/,/^.*User\ Contributed\ Notes/p | grep -v 'User\ Contributed\ Notes'
~/.vimrc:
autocmd FileType php set keywordprg=~/.vim/php_doc
Hi, This is a tweak on earlier tweak's. Rather than running in the shell, the following vimscript function run the help in a split so it more similar to vim help (and easier to cut and paste from). It's also plain vimscript so all you need to do is put it in your vimrc
fun! OpenPhpFunction (keyword)
let proc_keyword = substitute(a:keyword , '_', '-', 'g')
exe 'split'
exe 'enew'
exe "set buftype=nofile"
exe 'silent r!lynx -dump -nolist http://www.php.net/manual/en/print/function.'.proc_keyword.'.php'
exe 'norm gg'
exe 'call search ("' . a:keyword .'")'
exe 'norm dgg'
exe 'call search("User Contributed Notes")'
exe 'norm dGgg'
endfun
au FileType php map K :call OpenPhpFunction('<c-r><c-w>')<CR>
