schlitt.info - php, photography and private stuff ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :Author: Tobias Schlitt :Date: Fri, 09 Jan 2009 11:00:51 +0100 :Revision: 3 :Copyright: CC by-nc-sa ==================================== Comfortable PHP editing with VIM -3- ==================================== :Description: It's time to continue my series, since I again updated my .vimrc in the past weeks for much more comfortable editing of PHP sources using VIM. There are several new features I added: It's time to continue my `series`__, since I again updated my `.vimrc`__ in the past weeks for much more comfortable editing of PHP sources using VIM. There are several new features I added: .. __: /opensource/blog/0283_comfortable_php_editing_with_vim_2.html .. __: /misc/.vimrc - Auto completion of functions using - Auto reloading of .vimrc when changed - Enclose visually selected text by braces/quotes - Much more convenient scrolling through autoclosing folds - Search the PHP manual directly in VIM using phpm - Added settings for misconfigured machines - More convenient creation of phpdoc blocks with correct indenting and automatic ``*`` chars To use some of this (and the older) features, you will have to download `Rasmus' function list`__ and install `phpm`__ (which is very easy). .. __: http://lerdorf.com/funclist.txt .. __: http://www.wiki.cc/php/Epc_phpm Thanks a lot to everyone on the web providing me with support/tips! For detailed information on what has changed, please read the extended entry. A short hint for those of you who fight with auto completing enclosing chars (braces/qutotes) when you only want 1 exemplar: Use -v + the char to get only 1 of it! Sadly I lost a link I found while browsing the web where a script allows you to jump to PHP compile errors when running PHP CLI from VIM. Maybe someone can help me out? **Update**: There were some missing in the -p mapping for running PHP CLI on the current file. I fixed that and replaced the `download`__ with version 1.1pl1. If anyone finds more bugs, please comment on this blog entry or email me! .. __: /misc/.vimrc --------------------------- Auto completion using --------------------------- Bash users (as I am) are used to get their commands automatically completed when hitting the key after typing parts of a command. This works in VIM's command mode, too. Until now, you needed to remember that -k is used in insert mode to complete function names (using VIM's dictionary feature). From now on you will not have to change your practice, since auto completion will work using . Since the key is also used for indenting, a function in the .vimrc determines automatically, if you want to indent code (you are at the start of your code in the line) or complete a function name. In those rare cases where you really need a not for indenting you can simply use -v + . ------------------ Auto reload .vimrc ------------------ Everytime you changed your .vimrc you usually have to either restart VIM to make changes take effect, type all changes manually into command mode or reload .vimrc using *:source ~/.vimrc* (which is of course the easiest way). Having this new feature, your .vimrc will automatically be reloaded when you save it. ----------------------------------------------- Enclose visually selected text by braces/quotes ----------------------------------------------- Sometimes you want to include text you already typed text into braces or (more likely) into quotes. Using this feature you can simply mark the text (go into visual mode using v/-v/-v/... in command mode) and type the char you want to wrap around the text (like ( for (), ' for '',...) and it will be enclosed. Thanks to a commentor on `this`__ blog entry. .. __: http://www.jellybob.co.uk//index.php?gadget=Blog&action=SingleView&id=12 --------------------------------------------------- More convenient scrolling through autoclosing folds --------------------------------------------------- The new version of my .vimrc has folding activated by default, using fold markers ({ { { and } } }). Since I often have to edit huge files I let folds get automatically closed, when I leave them. This is really cool since you always have a great overview on your code (presumed that you have convenient fold markers). But in some way it's a bit nerving, that you accedentally move out of a fold by scrolling out of the screen (you maybe don't see the fold ending). A new setting will automatically scroll 5 lines further, when you hit the end of the screen. And another option indicates moving out of the screen 3 lines before you really hit it. Using this, you always have a good overview on the context of your currently line and see fold endings before you hit them. ------------------------------------------------ Search the PHP manual directly in VIM using phpm ------------------------------------------------ `phpm`__ is a neat little tool which allows you to search the PHP manual for functions from the shell. This enables you to simply run ":!phpm function_name" in command mode and see the prototype of the function. In the new version of my .vimrc I added a mapping for phpm which will show you the prototype of the function your cursor is currently on. You can simply type a function name (or the start of it, e.g. "mysql\_"), type -h and phpm will show you the prototype. .. __: http://www.wiki.cc/php/Epc_phpm `phpm`__ is provided by Havard Eide and can be downloaded `here`__. It needs PHP5. .. __: http://www.wiki.cc/php/Epc_phpm .. __: http://eide.org/?epc=php ----------------------------------------- Added settings for misconfigured machines ----------------------------------------- I recently had to edit some files on a somewhat misconfigured machine, where I had some wired problems with deleting already existant text and deleting empty lines. Some new settings in .vimrc fix this behavior for you, if you once run into the same problem: *:set backspace=start,eol* ------------------------------------------------------------------------------------------ More convenient creation of phpdoc blocks with correct indenting and automatic ``*`` chars ------------------------------------------------------------------------------------------ When usually creating phpdoc blocks for your code blocks you have to manually move the cursor on blank forward in the second line and manually add the ``*`` chars at the start of each line. A new setting in .vimrc will do that automatically for you. .. Local Variables: mode: rst fill-column: 79 End: vim: et syn=rst tw=79 Trackbacks ========== - Comfortable PHP editing with VIM -3- - Tobias Schlitt - Weblog on Mon, 23 May 2005 22:18:59 +0200 in Cease to Desist. Comfortable PHP editing with VIM -3- - Tobias Schlitt - Weblog Toby has done it again, with an even better .vimrc for people using “the one true editor” to write their code. The addition of phpm seems pretty cool, specially for me, as I d... - Comfortable PHP editing with VIM (from Tobias Schlitt) on Tue, 26 Jul 2005 23:47:52 +0200 in markus' blog Tobias Schlitt has put together some really useful information how to enhance vim to you can get more productive with vim. Don't miss his articles: Comfortable PHP editing with VIM Comfortable PHP editing with VIM -2- Comfortable PHP editing wi... - PHP IDEs: taking stock on Mon, 08 Aug 2005 22:26:20 +0200 in Peter Bowyer's weblog OK, what's happened since my last post? Well, I've been busy coding, using the Zend IDE exclusively. It hasn't crashed once, although javaw.exe is taking up between 65 and 120Mb of RAM which is making my computer sluggish at times. I've been recommended to look at TruStudio, so I will give that a test. It's also been pointed out that if I'm going to use the IDE a lot then limiting the price and ending up with something that doesn't help much is not a good idea. While the thought of spending a few hundred pounds on an IDE goes against the grain (particularly when I want to get Photoshop CS2) I understand the point being made, and have therefore removed my price limit. What's my current testing list look like? Zend Studio 4.02 PHPEd Eclipse with Xored TruStudio Eclipse with PHPEclipse Gvim (putting it off, but will use these tips) Maguma (maybe, but getting doubtful as no help from their support) ActiveState Komodo VS.Php One question that keeps coming up is "Can the editor be Windows-only, or does it have to be cross-platform?". My current thinking is that Windows only is fine, because although I have enjoyed playing with a Linux desktop, I run Windows XP on my main machine and have no reason to change. Maybe I'm going for a too heavy environment, and an editor with a debugger would do. I don't know, it throws out a whole load of extra options to evaluate... It's time to take stock of my requirements again. This list is going to grow over the next few days as I think of them (I really should have written them down as they came to me while coding). Requirements It must offer code insight to files within PHP's include_path (eg PEAR libraries). This saves me going online to the manual every time to check the syntax… and if the editor's smart enough to compile a dictionary of functions/classes/methods in these files rather than rescanning the file every time, so much the better. I would really like debugging which can be built into the server. So when something stops working in my home-grown application framework, I can use a debugger to see what's going on in each file, rather than adding print and print_r statements to many files. Code templates - so I don't have to type every character in a foreach loop or class statement for example. Most editors provide this. Non-requirements CVS integration - I use TortoiseCVS and TortoiseSVN which integrate beautifully wherever the Windows file browser is used. Bloat. Stupid memory usage is out. Although judging by the performance of the market leader, I can't be too picky on this. Would be nice to have Code folding. It does make moving around long files nicer. UML/refactoring. A vague requirement because I don't really know what I'm talking about, but I've reached the point where I see an advantage in using UML while designing/planning. Like most things, and however hard I try not to, I am looking for perfection. I know I'm not likely to find the perfect IDE out there ( in a perfect world I wouldn't be using PHP ) but something that suits and speeds up my development.... - Comfortable PHP editing with VIM -4- on Fri, 16 Sep 2005 16:23:51 +0200 in Tobias Schlitt - a passion for php 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 usu - Comfortable PHP editing with VIM -5- on Wed, 23 Aug 2006 16:41:19 +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 - 3 years of blogging on Sat, 30 Sep 2006 11:57:48 +0200 in Tobias Schlitt - a passion for php Yes, it's true, exactly 3 years ago I wrote my first blog entry. By that time I would never have imagined, that I would keep blogging for more than 3 years and that more or less constantly. My weblog now contains 458 entries. Surely, there is some bulshit - PHP Documentor for VIM documented on Fri, 01 Dec 2006 11:49:42 +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 - Tramadol. on Tue, 05 Feb 2008 12:45:14 +0100 in Tramadol cod. Comparative potencies of opioids tramadol. Tramadol side affects. Tramadol. Comments ======== - Sam Rowe at Sat, 21 May 2005 22:40:30 +0200 VIM already maps 'k' to "look up the word under the cursor with man." So if the filetype is PHP, I set keywordprg to w3m pointed at php's manual. I described it here: http://deadman.org/scripts/php_vars.vim If you put that file in ~/.vim/ftplugin (and your version of Vim supports it) it should get automatically sourced whenever you're editing a php file. Culley Harrelson also wrote a handy script for editing PHP in Vim that you can find on vim.org. remapping ctrl-b is only useful if you don't use ctrl-f/ctrl-b for paging.. - Toby at Sun, 22 May 2005 16:42:04 +0200 Having a lookup of functions only when online sounds a bit odd, since I code most of the time when being offline, so the phpm solution is more convenient. Can you point me to that script on vim.org directly? Your issue regarding ctrl-b is fixed in version 1.1pl1. Thanks for the hint! - Sean Coates at Sun, 22 May 2005 17:20:43 +0200 You might find these interesting: http://cvs.php.net/co.php/phpdoc/funclist.txt?r=1.35 http://cvs.php.net/co.php/phpdoc/funcsummary.txt?r=1.27 S - Wez Furlong at Mon, 23 May 2005 16:58:00 +0200 I use this in my .vim/after/plugin/php.vim file (which gets sourced after all the regular stuff): augroup WezsPHPStuff au BufEnter *.php set complete-=k~/.vim/php-funclist.txt complete+=k~/.vim/php-funclist.txt au BufLeave *.php set complete-=k~/.vim/php-funclist.txt au BufEnter *.inc set complete-=k~/.vim/php-funclist.txt complete+=k~/.vim/php-funclist.txt au BufLeave *.inc set complete-=k~/.vim/php-funclist.txt augroup END What does it do? It only applies the php function list completion to buffers that contain php code, as it's really annoying to have php functions complete in a buffer containing C code :-) As Sean pointed out, you can get a more up to date function list from the phpdoc repository: wget 'http://viewcvs.php.net/viewcvs.cgi/*checkout*/phpdoc/funclist.txt' -O php-funclist.txt.new cat php-funclist.txt.new php-lang-constructs.txt | egrep -v '^#' | sort | uniq > php-funclist.txt Where php-lang-constructs.txt contains: echo print foreach list new (language constructs are not implemented in the same way as the other functions, so the phpdoc tools can't pick them up from the source). - Toby at Mon, 23 May 2005 22:58:44 +0200 Inspired by a trackback from here: noremap ; :s/\([^;]\)$/\1;/< cr > This will add a ; to the end of the current line, when there is none. This hack will definitly be part of my .vimrc 1.2. - Bryan at Tue, 24 May 2005 06:08:30 +0200 I'm having trouble using the folding.. the problem is that when I type a left brace, it automatically inserts a carriage return and creates a closing brace (which is good if I'm writing a function, etc.). Is there some way to type 3 consecutive opening braces without invoking the automatic carriage return? - Toby at Tue, 24 May 2005 09:03:23 +0200 Simply use CTRL-V + (/{/[/"/' to type only the opening part (as it's said in the article! :) - Bryan at Tue, 24 May 2005 17:26:48 +0200 Thanks.. I swear the CTRL-v wasn't working before.. I was just getting a visual block. It works fine now though. - Toby at Tue, 24 May 2005 17:38:10 +0200 Hmm... wired... Maybe you were in command mode (ctrl-v then indicates creating a visual block)? No matter, now it's working! :) Have fun! :) - mitjok at Tue, 21 Jun 2005 15:07:03 +0200 When I use code temlates, e.g. =cla, I get * doubled from the 2nd string: /** * * class * * @access * * @package * * @since * */ - John Wellesz at Fri, 24 Jun 2005 00:22:24 +0200 If you want correct indenting for PHP with VIM you may be interested by my script: You can find a detail description of what it can do: http://www.vim.org/scripts/script.php?script_id=1120 or http://www.2072productions.com/?to=phpindent.txt - Will at Mon, 01 Aug 2005 12:36:17 +0200 I've downloaded the function list, and I located it on my disk two times in the .vimrc file and it doesn't work? I also seem to be getting: Error detected while processing /Users/william/.vimrc: line 122: E20: Mark not set line 123: E20: Mark not set line 143: E492: Not an editor command: (then tab indents) or line 162: E492: Not an editor command: that line 169: E20: Mark not set line 171: E488: Trailing characters: */require_once '; line 175: E20: Mark not set line 177: E488: Trailing characters: */include_once '; line 181: E492: Not an editor command: public*/define (', ';?',i line 185: E492: Not an editor command: {?/\*\*/ \* $i line 189: E492: Not an editor command: public* @param * @return void*/public function line 190: te function _ line 193: E492: Not an editor command: ({?/\*\*/ \* $i line 197: E488: Trailing characters: */public $ = ;?/\*\*/ \* $i line 199: E488: Trailing characters: */private $_ = ;?/\*\*/ \* line 251: E488: Trailing characters: */public $ = ;?/\*\*/ \* $i line 253: E488: Trailing characters: */private $_ = ;?/\*\*/ \* $i line 266: E488: Trailing characters: '':break;default:break;}/)i line 270: E492: Not an editor command: {}/)i Any ideas why? - Toby at Mon, 01 Aug 2005 12:57:44 +0200 Looks like to tryed including the funclist instead of adding it to your dictionary...? The inclusion should look like this: set dictionary-=/home/dotxp/funclist.txt dictionary+=/home/dotxp/funclist.txt " Use the dictionary completion - John Wellesz at Tue, 09 Aug 2005 00:14:30 +0200 Ok, I have a good news for all PHP programmers: my script will be included by default in Vim 7 :-) http://www.vim.org/scripts/script.php?script_id=1120 John - Adrian at Thu, 20 Oct 2005 20:05:51 +0200 Great stuff! But I think the funclist.txt of Rasmus is incomplete. I'm not sure what exactly is missing, but I grabbed all linked functions from http://php.net/manual/en and got nearly 1.500 functions more than listed in Rasmus file: http://www.kurzefrage.de/~as/contrib/phpfunclist.txt - Christian at Sat, 08 Jul 2006 18:19:38 +0200 Hey, don't you wanna upload your .vimrc again? :-) I would like it, Chris - Toby at Sat, 08 Jul 2006 19:32:10 +0200 Please look here for the latest version: http://www.schlitt.info/applications/blog/index.php?/archives/372-Comfortable-PHP-editing-with-VIM-4.html - Torgeir at Tue, 19 Sep 2006 15:13:43 +0200 This looks great! but as trying to find out how you did all this neat stuff i cant help to notice that your .vimrc-link is not working.. This would be of great help - Toby at Tue, 19 Sep 2006 15:17:19 +0200 You should look into the latest entry: http://schlitt.info/applications/blog/index.php?/archives/488-Comfortable-PHP-editing-with-VIM-5.html It has a link to my SVN. - Torgeir at Tue, 19 Sep 2006 15:26:46 +0200 oh, fast reply.. thanx :) - CoreSh at Mon, 22 Dec 2008 08:34:45 +0100 The full Php functions updated method: # wget -qO - http://www.php.net/manual/en/indexes.php | grep '
' | grep -oP '>(.*)\(\)<\/' | sed 's/>