Comfortable PHP editing with VIM -6- - Blog - Open Source - schlitt.info

schlitt.info - php, photography and private stuff

Comfortable PHP editing with VIM -6-

I recently added 2 new functions to my PHP FTPlugin for VIM, which I wanted to implement for a longer time and recently needed quite often:

PhpAlign()

Often you have written down an array declaration or a set of variable assignements. Usually things look somewhat ugly the, like

$foo = array( "test" => "test", "foo" => "bar", "something" => "somewhat", "anything more" => "and more and more", );

Aligning this definition properly is an ugly, boring work. The PhpAlign() function takes it from you and aligns the array declaration properly:

$foo = array( "test" => "test", "foo" => "bar", "something" => "somewhat", "anything more" => "and more and more", );

This also works with usual variable assignements:

::

$foo = "bar"; $someVariable = "some value"; $aVar = 23;

becomes

$foo = "bar"; $someVariable = "some value"; $aVar = 23;

PhpUnComment()

Often you want to comment or un-comment a couple of lines, because you currently change those and want to make a backup or simply want to bring alternative code in place. For multiple reasons you may not want to use multi-line commens for this (e.g. because you the closing sequence inside the code or because they simply look ugly. PhpUnComment() simply comments a line which is not commented and un-comments a line that is commented.

function test() { return "test"; } // function test() // { // return 23; // }

Selecting these lines (all of them) and running PhpUnComment() results in:

// function test() // { // return "test"; // } function test() { return 23; }

Both function are mapped to shortcuts in visual mode (<Ctrl>-a for PhpAlign() and <Ctrl>-c for PhpUnComment()), if you are using my FTPlugin.

The changes are already included in my SVN and documented there, too. Do get a recent checkout do:

$ svn co svn://svn.toby.phpugdo.de/PDV

If you liked this blog post or learned something, please consider using flattr to contribute back: .

Trackbacks

Comments

Add new comment

Fields with bold names are mandatory.