Sunday, October 23, 2005

Vim and phpm

I've been using linux for a few years, and since the first time I installed it on my computer I learned using VIM. Its name stands for VI iMproved, and it is a very powerful editor, especially for programmers. Often I find myself seeking on www.php.net for php functions prototypes, I can't always remember them all: so, surfing some blogs I found this useful "vim extension", phpm. What's that ?

phpm is a little command line tool that uses a XML file that stores php function prototypes, returning it when you run the command this way:

$ phpm <part_of_function_name>


- how to install it

· download the package http://eide.org/files/phpm/phpm_0-3.tar.gz, untar it;
· edit phpm/phpm file (bash script), and replace the second line with a path where you have write permission (i.e. $HOME/phpm/phpm);
· download the xml pack (from the same site), untar it where you like;
· edit phpm/settings.xml, at line 27 change the "install path" to the path where you untar'd the xml pack;
· add the next line at the end of your $HOME/.vimrc (vim initialization file):

inoremap <C-H> <ESC>:!phpm <C-R>=expand("<cword>")<CR><CR>


all done :)

from now on, where you're writing a function name in a vim session, simply press CTRL+H when the cursor is on the function name string, and the function prototype will appear in a vim shell window.


final considerations:

phpm is a useful tool, the integration with vim is easy. The solution here provided ("stolen" around the web) is good, but I think it'd be better if the function prototype appeared on the same vim editor windows, and not in a "Hit ENTER or type command to continue" shell window. For example, it could be written on a sort of status bar in the main vim window: I think that's possibile and easy to realize, I think a bit of hack on the vim resource file will do the trick. I'll let you know.

Update:

I'm starting to understand vimrc syntax, and the next line makes the php function prototype on the window statusline. I think now phpm vim integration is nicer than the example reported above in this post:

inoremap <C-H><ESC>:let phpm=system("phpm ".expand("<cword>"))<CR><ESC>:set statusline=%{phpm}<CR><ESC>i

0 Comments:

Post a Comment

<< Home