welcome in my blog....

Sabtu, 06 Juni 2009

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 (-a for PhpAlign() and -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

Trackbacks

  • Integrate PHP CodeSniffer in VIM

    on Tue, 11 Mar 2008 16:25:30 +0100 in Thomas Koch

    You can integrate PHP Codesniffer in your VIM with the following code:

    CODE:function! RunPhpcs()
        let l:filename=@%
        let l:phpcs_output=system('phpcs --report=csv&#

Comments

  • Pento

    on Mon, 30 Apr 2007 06:49:00 +0200

    Tobias, can you remove html entities from code?

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

  • Toby

    on Mon, 30 Apr 2007 07:42:22 +0200

    Hi Pento!

    What is the actual problem? Do you see the entities in your browser or something?

    Regards,
    Toby

  • gen2brain

    on Mon, 30 Apr 2007 10:46:17 +0200

    Yeah, i see them too, Firefox 2.0.0.3, in IE6 everything is ok.

  • Dietrich

    on Mon, 30 Apr 2007 10:49:05 +0200

    The code is full of span class="serendipity_searchQuery" tags which break all the entities into pieces.

  • Toby

    on Mon, 30 Apr 2007 10:56:21 +0200

    Seems the problem occured wizth the Serendipity "search highlight" plugin. Thanks for the hint, I deaktivated the plugin now.

  • Benjamin

    on Fri, 04 May 2007 10:08:40 +0200

    Where can we get phpm? =/ All the links on the web are DEAD. Any suggestions?

  • Toby

    on Fri, 04 May 2007 10:59:37 +0200

    I'm sorry, I could not reach the maintainer of PHPM, too. I think I will re-implement PHPM if I find time...

    Regards,
    Toby

  • Benjamin

    on Fri, 04 May 2007 22:04:09 +0200

    It's a share. It seemed like such a great tool for php/vim users. I haven't been able to find anything else that gives the function prototypes. Anyone found/using anything?

  • aizatto

    on Sat, 12 May 2007 13:43:08 +0200

    There is already an alignment plugin for vim http://vim.sourceforge.net/scripts/script.php?script_id=294

  • Toby

    on Sat, 12 May 2007 14:42:35 +0200

    Ah, thanks, did not see that. I will dig into it and see if I should better use this one! :)

  • Clayton

    on Tue, 12 Jun 2007 18:51:10 +0200

    Just a comment that the example usage displayed in php-doc.vim should contain
    ":call PhpDoc()" instead of ":exe PhpDoc()"
    It will try to execute the returned string when using :exe

  • Toby

    on Tue, 12 Jun 2007 20:36:30 +0200

    Thanks for the hint! I updated the example!

  • Clayton

    on Tue, 19 Jun 2007 23:41:30 +0200

    for all the [inv]noremap mappings, I would change them to:
    [inv]noremap .....

    the reason for this is so that when I use my mapping it will only apply to php files instead of every new buffer I work on.

    test by doing :sp blah.c then
    read about it, :h

    and, I need for autocompletion so I use instead.

    neither of the above are extremely significant but may be useful to any googler passing through

Tidak ada komentar:

Posting Komentar