schlitt.info - php, photography and private stuff ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :Author: Tobias Schlitt :Date: Thu, 27 Nov 2008 18:00:29 +0100 :Revision: 2 :Copyright: CC by-nc-sa ==================================== Comfortable PHP editing with VIM -4- ==================================== :Description: It's nearly 4 month ago now, since I last blogged about my .vimrc (the main Vim config file) and the recent enhancements I added to it. This time, I go a step further as in the last 3 parts: I wrote my first own Vim script. :) Beside that there are as usual some other great enhancements and tips I collected over the past 4 month and I already have an idea of how to proceed and what I need more. But first, I'd like to give a brief changelog between version 1.3 and the last version: It's nearly 4 month ago now, since I last `blogged`__ about my .vimrc (the main Vim config file) and the recent enhancements I added to it. This time, I go a step further as in the last 3 parts: I wrote my first own Vim script. :) Beside that there are as usual some other great enhancements and tips I collected over the past 4 month and I already have an idea of how to proceed and what I need more. But first, I'd like to give a brief changelog between version 1.3 and the last version: .. __: /opensource/blog/0331_comfortable_php_editing_with_vim_3.html - Fixed bug with cover char mapping of "" in visual mode. - Mapped ; in command mode to check if the current line ends with a semicolon and to add it, if it's missing. - Configured :make command to run "php -l" and jump to the line of the first compile error afterwards. - Added setting for not highlighting every search result (which is a Gentoo standard setting). - Added laststatus=2 which makes a nicer ruler (thanks Derick!). - Moved PHP specific settings to a file type plugin in .vim/ftplugins/php.vim (only global options are left in the .vimrc itself). - Activated automatic sourcing of ftplugins (so that the php.vim is included for PHP files). - Added file type setting for .phps files to PHP. - Added possible alternatives for other coding standards for mappings of {} and (). These changes are mostly of cosmetic nature and the real enhancement is the script I wrote. I was searching for a longer time for a really convenient documentation plugin to let Vim generate phpDoc conform doc blocks for my classes/functions/methods/... . Sadly I did not find anything beside the scripts by `Karl Heinz Marbaise`__ and `Vidyut Luther`__, which both did not satisfy my needs or even almost work. So I started hacking around in Vidyut's script to fix it and the result was **PDV (phpDocumentor for Vim)**, a complete rewrite. `PDV version 1.0.0`__ supports the following features: .. __: http://www.vim.org/scripts/script.php?script_id=520 .. __: http://www.phpcult.com/downloads/vim/php-doc.vim .. __: http://www.vim.org/scripts/script.php?script_id=1355 - Generation of phpDocumentor conform docs for - Classes - Methods/Functions - Attributes - Supporting for PHP 4 and 5 syntax elements. - Define default values for phpDocumentor tags like @version (I use $id$ here), @author, @license and so on. - For function/method parameters and attributes, the script tries to guess the variable type as good as possible from PHP5 type hints or default values (for array, bool, int, string...). - Generating doc blocks for single lines, all known elements in a visual selection and over a whole file (where in the latter cases existing documentation is taken into account). I'll provide a copy of this script with my blog series in combination with my .vimrc and the FTPlugin, but maintain the script itself independantly on `vim.org`__. More features will surely come soon (I already planned support for constants and some other constructs, as well as documenting whole directories and some more stuff)! .. __: http://www.vim.org/scripts/script.php?script_id=1355 You can download my actual .vimrc-package (since it's no more only a single file) `here`__ (CAUTION: If you already have a .vimrc, don't extract this package directly to your home diretory!). .. __: /misc/.vim.tar.bz2 Last for today, some tipps for using Vim: - All those enhancements (especially auto-indent and close char mapping) make it more or less impossible to paste text from other application to Vim. Thanks to Derick who showed my the settings ":set paste"/":set nopaste", which switch all enhancements off for insert mode. - Jakob Westhoff (from our local user group) told me about the combination + in visual mode, which wraps the selected parts into Vim fold-tags. Sadly this does not create the tags like I want it by now, but I guess I can change that somehow. Hope you like it, 'till next time! P.S.: I'll maybe write an extended entry for this one, when I find time, to explain the features in detail. **UPDATE**: Because of so many questions about it: The link to my .vimrc above is outdated. Please refer to my `SVN repository`__ for a recent version! .. __: http://svn.toby.phpugdo.de/PDV .. Local Variables: mode: rst fill-column: 79 End: vim: et syn=rst tw=79 Trackbacks ========== - VIM - still a choice for PHP programmers on Sat, 17 Sep 2005 16:13:24 +0200 in Rombert is a geek Maybe you though that VIM is obsolete, and that power PHP programmers use large, expensive, highly integrated point'n'click IDEs. Think again. Tobias Schlitt has a series of articles about Comfortable PHP editing with VIM which may change your opinion abo - PDV - phpDocumentor for Vim on Sat, 17 Sep 2005 16:52:09 +0200 in The phpcult PDV - phpDocumentor for Vim - Provides generation of phpDocumentor doc blocks for PHP4 & 5. Tobias Schlitt has rewritten my vim phpDoc plugin. I’ve been testing it for a few days now, and it’s a lot better than what I had. It does ... - PDV example on Sat, 17 Sep 2005 20:46:14 +0200 in Tobias Schlitt - a passion for php I just realized that I missed to show some examples for my phpDocumentor for Vim plugin. So, here they are: Before using PDV. After visually selecting the whole file and running PhpDocRange?() (all options switched to on, you can adjust your output segn - They must think I'm cheating... on Sun, 18 Sep 2005 23:56:02 +0200 in Tobias Schlitt - a passion for php PDV (phpDocumentor for Vim) ran into the top 10 PHP Vim scripts on vim.org within 2 from it's first publishing... and I did not even vote once... that's a bit scary, isn't it? - documentation on Tue, 25 Oct 2005 23:09:09 +0200 in Kai Rautenberg - wo weblog is gut es gibt 3 verschieden Kommentarzeichen in php, die scheinbar unerschöpfliche Kombinationsmöglichkeiten von Funktionsheadern zulassen. Als bugbuster bei myfotofactory komm ich nicht drum rum sie lesen zu müssen.Um so schöner ist jetzt meine heutige Entde - PHP und VIM on Fri, 18 Nov 2005 00:21:56 +0100 in EvilEds wirre Gedanken Heute bin ich endlich mal dazu gekommen die .vimrc von Tobias Schlitt zu testen. In seinem Blog hat er mehrfach ausführlich darüber berichtet. Schön ist neben der Code-Completition auch die Einbindung von phpDocumentor. Jedem PHP-Entwickler kann ich - Vim buat PHP koder on Sat, 08 Jul 2006 23:23:03 +0200 in :: Sayid Munawar :: c|>>><<<|3NuL|_ Tips and tricks vim buat PHP koder: Prerequirement: PHP versi 5 cgi/cli Instal php vimrc punya e tobias di sini. cara install phpm: downlod di http://eide.org/view/php download semua xml nya, edit settings.xml, phpm (set path) Tambahkan PHP - Comfortable PHP editing with VIM -5- on Wed, 23 Aug 2006 16:32:33 +0200 in Tobias Schlitt - a passion for php More than a half year after my last "Comfortable PHP editing with VIM" post, I take up this series again, although I decided to let it die in January. Sadly I did not find any time by now, to extend PDV (the PHP Documentor for VIM plugin) furthe - PHP Documentor for VIM documented on Fri, 01 Dec 2006 11:49:41 +0100 in Tobias Schlitt - a passion for php Because I had a talk about how to use VIM in respect to PHP source code editing, I took the time during the week, to write some extensive documentation for PDV, the PHP Documentor plugin for VIM. Additionally, I documented my VIM file type plugin, which i Comments ======== - jerik at Sat, 17 Sep 2005 20:20:20 +0200 [/quote] Mapped ; in command mode to check if the current line ends with a semicolon and to add it, if it's missing. [/quote] Hej funny. I had the same idea some weeks ago, but i didn't think to include a check. Good idea - i will implement this as well. Nice work. * due the fact that the moinmoin Wikiformating (http://projects.edgewall.com/trac/wiki/WikiFormatting) didn't work, i just used bb-code. Cheers jerik PS: Vim Rules !! - armen at Mon, 03 Oct 2005 20:50:27 +0200 nice work man. I found a little bug in PDV! when my parent class named with underscore like OSC_Model PDV generate incorrectly result. please add folding capabaliti for your wonderful PDV, Tanks. PS: Sorry for my bad english ;-( - Charles at Mon, 05 Dec 2005 03:47:28 +0100 Hi, nice idea about the ';' map :]. Here's another mapping to show the result inside Vim window ^_^ map ;; :echo system("php -l ".expand("%")) - caillou at Tue, 31 Jan 2006 21:40:15 +0100 thank you for all of this... i will have to study that fore several evenings. you might just want to add the following lines into the general purpose .vimrc ... that way, you have standard syntax hiLight on, when editing files non specified by the files in the .vim/ftdetect ... such as the .vimrc itsel ;) " let vim have colors let color = "true" if has("syntax") if color == "true" so ${VIMRUNTIME}/syntax/syntax.vim else syntax off set t_Co=0 endif endif - jm3 at Sun, 01 Oct 2006 00:00:10 +0200 does this correctly handle syntax-coloring "less-than sign", "greater-than sign", and -> occuring within php blocks? - jm3 at Fri, 01 Dec 2006 16:07:57 +0100 AKA, does it correctly color "ASP-style" tags in PHP? - Toby at Fri, 01 Dec 2006 22:48:29 +0100 Nope, I don't think so. Do not use them! Just use the correct PHP tags! - jm3 at Fri, 01 Dec 2006 23:35:32 +0100 Oh. Why do you suggest not using them? They are easier to type, compatible with JSP & ASP, and PHP has supported them just fine since version 3.0.4. - Toby at Sat, 02 Dec 2006 00:00:03 +0100 Because you are writing PHP, not ASP or JSP. :) Additionall, if you write an application for more than personal use (distribution, open source, custumers,...) you can never be sure that a server your application is deployed to supports them. So your application becomes a lot less portable. Beside that, (almost?) all major PHP projects discourage all other tags except the official PHP tags and it is commonly considered good coding manor to use those. - Toby at Sat, 02 Dec 2006 00:02:37 +0100 Another side note: ASP tags will be gone in PHP 6. See http://php.net/~derick/meeting-notes.html#id66 - Francis Reyes at Mon, 04 Dec 2006 16:40:25 +0100 The download link for your .vimrc package is broken? - Toby at Mon, 04 Dec 2006 16:45:17 +0100 Please download it from SVN: http://svn.toby.phpugdo.de/PDV/. Beware, I splitted the .vimrc to the actual file and the FTPlugin in addition (.vim/ftplugin/). - Francis Reyes at Mon, 04 Dec 2006 19:32:58 +0100 chem91-77-dhcp:~ ruckerz$ svn checkout http://svn.toby.phpugdo.de/PDV/ svn: PROPFIND request failed on '/PDV' svn: PROPFIND of '/PDV': 301 Moved Permanently (http://svn.toby.phpugdo.de) chem91-77-dhcp:~ ruckerz$ ? - Toby at Tue, 05 Dec 2006 12:33:27 +0100 Sorry, that is only for web access. Checkouts can be done like this: svn co svn://phpugdo.de/PDV That is because I run Lighttpd and not Apache. ;) - Tarjei Huse at Sat, 17 Feb 2007 12:19:24 +0100 I love your series, but I never manage to get the command mappings to work. When I try to write f.x. =roc nothing happens. I believe I've got some simple thing wrong here. Does anyone have a tip on how to debug command mappings? Also, have you looked at this script for autoindenting php? http://www.vim.org/scripts/script.php?script_id=1120 - Toby at Tue, 16 Feb 2010 08:55:30 +0100 Note that PDV is now named VIP and hosted on github. For details, please refer to http://schlitt.info/opensource/blog/0719_pdv_vip_now_on_github.html