schlitt.info - php, photography and private stuff ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :Author: Tobias Schlitt :Date: Wed, 19 Nov 2008 23:29:46 +0100 :Revision: 1 :Copyright: CC by-nc-sa ==================================== Comfortable PHP editing with VIM -6- ==================================== :Description: 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: 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: .. __: http://svn.toby.phpugdo.de/PDV $ svn co svn://svn.toby.phpugdo.de/PDV .. Local Variables: mode: rst fill-column: 79 End: vim: et syn=rst tw=79 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&# - PDV → VIP, now on github! on Tue, 16 Feb 2010 08:54:08 +0100 in schlitt.info - php, photography and private stuff phpDocumentor for VIM (PDV) is a project which resulted from my efforts to create a comfortable programming environment for PHP in the VIM editor. Since the server which hosted the SVN repository is to be switched off the next days, I finally moved development over to github.In addition to that, I seized the chance to rename the project itself to VIP (VIM integration for PHP). The repository does not only contain the PDV script iself, but also a filetype plugin for PHP, some useful color schemes, a PHP skeleton file, settings for other (related?) programming languages and more. Comments ======== - Pento at Mon, 30 Apr 2007 06:49:00 +0200 Tobias, can you remove html entities from code? > $foo          = "bar"; $someVariable = "some value"; $aVar         = 23; - Toby at 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 at Mon, 30 Apr 2007 10:46:17 +0200 Yeah, i see them too, Firefox 2.0.0.3, in IE6 everything is ok. - Dietrich at 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 at 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 at Fri, 04 May 2007 10:08:40 +0200 Where can we get phpm? =/ All the links on the web are DEAD. Any suggestions? - Toby at 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 at 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 at 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 at 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 at 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 at Tue, 12 Jun 2007 20:36:30 +0200 Thanks for the hint! I updated the example! - Clayton at 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 - Fery at Sun, 29 Nov 2009 16:05:37 +0100 Hi Toby... I'm a newbie Vim user looking forward to using it for editing PHP files. I checkout your vim-related files from your svn and explore it a bit. I wonder, if there is an easier way (keyboard-based) to write if / for / while / etc of-the-like-statements in Vim. With your .vimrc it goes something like this while ( $i >0 ) <$a> { After entering the conditional expressions (i>0) users need like 4 key-strokes just to type the {. And those keys are quite distant each other (Esc$a{). Could you tell me how to shorten it to fewer keystroke (if possible to 1 keystroke and nearby within finger reach on the alphabet keys, and without conflicting with your current key-mappings? Thanks in advance. (and your blog here is really helpful indeed for a Vim-newbie to quickstart Vim for PHP) - Toby at Tue, 16 Feb 2010 08:54:39 +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 - sound files download at Fri, 21 May 2010 10:46:22 +0200 Thanks, Jon! Please see Jörns entry for a better solution especially with {}. Jörns one does autoindent correctly. (Jon's entry was posted when the above so crappy shown > and < signs were not present due to some wired stuff in this blog-software.) - www.masculineshopping.com at Wed, 20 Jun 2012 10:54:51 +0200 I am researching this topic for use in a future business I am thinking about starting. Thank you for this information, it has been educational and helpful to me. - money saving at Thu, 28 Jun 2012 08:13:28 +0200 Very interesting article. Content has been written in very nice manner. I enjoy reading this kind of stuff. Thanks for sharing good knowledge. - www.unlockedpoker.com at Wed, 17 Apr 2013 05:31:55 +0200 All external expectations, all pride, all fear of embarrassment or failure - these things just fall away in the face of death, leaving only what is truly important - page univert broyeur at Wed, 24 Apr 2013 13:46:37 +0200 The author has written an excellent article. You made your point and not much to discuss. It's like this universal truth that you can not argue with the truth is not universal, everything has its exception. Thanks for this information. - www.internetbestservices.com at Thu, 25 Apr 2013 02:34:59 +0200 A member of the Democratic Party, he has been the Senate Majority Leader since January 2007, having previously served as Minority Leader and Minority and Majority Whip. - theseniorlifeinsurance at Thu, 25 Apr 2013 09:19:45 +0200 Lord Cope said the committee wanted UKTI and UKEF to “blow their own trumpets and promote their services for SMEs”, working with business organisations - weightlosscalculatorformen at Thu, 25 Apr 2013 09:20:03 +0200 The first thing you need to do to lose weight is to take control of your diet. Understand the decisions about what you put in your body directly relates to your obesity. Start making healthier decisions. Without a better diet, it's going to be extremely difficult for you to lose weight. - mybestdomainregistrar at Thu, 25 Apr 2013 09:20:21 +0200 Utilize databases in your home or office that will allow you to store data on your clients and customers. Many customers, when they connect with organizations, - cslawtalk at Thu, 25 Apr 2013 09:21:09 +0200 You need to realize that when you were born, your brain and mind didn't include anything negative. In other words, no one is born with negative thoughts stored somewhere in wait to develop. - www.downloadvideogames.eu at Thu, 25 Apr 2013 09:21:32 +0200 All of the games upon cooking possess interesting history and situation which will make the video games more thrilling. In the actual Homemade Pizzas game you have to cook the delicious as well as spicy pizza for that guests who've come to go to your home. - www.topphoneshops.com at Mon, 29 Apr 2013 07:24:50 +0200 I am about to complete a university thesis on this topic and your post has helped me with the facts and figures I needed to accomplish it. Cheers! - blackcircle tyres at Tue, 07 May 2013 10:52:41 +0200 I have always been extremely thrilled to feel right here because this is certainly a good website which offers many information regarding the topics covered detailed. --------------- - hotspot software at Wed, 08 May 2013 12:57:53 +0200 This plan is ideal for our customers for whom system availability is business critical, and who require software investment protection. - http://pinterest.com/louisvuitton05/ at Mon, 13 May 2013 07:51:00 +0200 Designer bags are popping up faster than you can say 'Louis Vuitton', in the hands of your friends, family, people you pass it. - Application Security at Wed, 15 May 2013 12:31:34 +0200 A website's security certificate gives users extended security by encrypting data between the user's browser and the Web server. Security certificates are installed on the server, so your website developers can securely transfer information such as financial or medical records.