Jun 032013

Since year 2000 I'm a big fun of vim editor, in that period I've switched from joe editor to the more powerful vim.

In that period I have used it mostly for PHP programming.
What was not quite OK was the fact that I did not have a PHP help "integrated" into my editor.
What I knew is that the documentation of C/C++ was easy accessible within vim.
In vim when editing C/C++ code just go the the name of a function/structure and press K (SHIFT + k) and magically you will notice the documentation of that word coming up.
The background of this behaviour: when "K" is pressed the vim editor will run the command "man $word" and the output of this command is shown in your editor ($word is the word where the cursor is placed)
The good thing is that the "K" bind key is configurable, all that we have to do is to run set keywordprg=/path/to/my_script in vim (or put it in vim.rc file for needed extensions) and when the "K" key will be press then the vim will run "/path/to/my_script $word".

The next good thing is that on PHP site if you need the documentation for a function or for a statement is enough to put in your browser an URL like http://www.php.net/$a_word (e.g. http://www.php.net/foreach http://www.php.net/printf ), and php.net will give you the documentation page.

So, for PHP extension I've run set keywordprg=/home/mark/my_php_doc and inside /home/mark/my_php_doc I have next couple of lines:

elinks http://www.php.net/$1

It will launch the elinks browser using URL http://www.php.net/$1
Now I have an online PHP help available, always up to date 😉 .

A lot of other things can be done here...
If there is not internet available (hard to believe it nowdays) instead of visiting http://www.php.net/site you can build your own script which will grep some local files and eventually will print the piece of file that you need to stdout (it will be redirected to your editor).
You can also extend the documentation with the function/classes from your own libraries, or for other languages than PHP you can search in the specific directories/files .

This is an old vim tip that I'm using since years, but few days ago talking with some other experienced vim users I've noticed that they were not aware of this feature of vim.
So, I felt the need to share it with other people.