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 ================================ :Description: I've always been a vi-hater, until I really came to know it. As most Unix newbes I first did not know in a way how to deal with vi in general and therefore never even touched it for years (I guess in the very first weeks, I did not even know, it exists). I've always been a vi-hater, until I really came to know it. As most Unix newbes I first did not know in a way how to deal with vi in general and therefore never even touched it for years (I guess in the very first weeks, I did not even know, it exists). After some month on Linux, someone threw me into cold water and told me to use vi for editing files and I tried, what resulted in the usual process (I imagine): 1. "Damn, now I'm in here, but I cannot type anything!" ``*``\argh``*``\ 2. "Bloody shit, I cannot even exit it anymore" ``*``\grmpf``*``\ By mid of this year some friends tried to evangelise me to use vi and, I bet you know, the were successful. Even that successful, that I bought "`Learning the vi editor`__"``*``\ a few weeks after they convinced me to try out vim. This is now nearly 6 month ago and I slowly start really getting used to some of it's neat functions and have some fixed set of settings, I'd like to provide to others. .. __: http://www.oreilly.com/catalog/vi6/index.html Beside the usual options like autoindent, smartindent, nowrap and number, I created some nice shortcuts (for checking PHP syntax and for running "pear package" directly from the editor. But the most important feature I really like is creating code skeletons on the fly, using key mappings. So, what does that basically mean? There are quite some constructs in PHP which you really use often, like if-statements, foreach-loops, class/method/attribute-definitions and so on. Usually people write that most of these once in a file (mostly with those definition parts) and then copy and paste the stuff. What I do since a few month now, is just typing (e.g.) "=cla" in vim's editing mode and a class defintion (including comments) appears and leaves me on a place where I can comfortably start filling it. Same for the other named constructs and some more. I guess I sped up my code-writing speed by about 15% with that and it's pretty comfortable. So, if you like, check my current .vimrc `here`__ and try it out! Feedback, additions and hints are pretty welcome! :) .. __: /misc/.vimrc ``*``\A big recommendation on that book to everyone out there who's new to vi or one of it's clones! .. Local Variables: mode: rst fill-column: 79 End: vim: et syn=rst tw=79 Trackbacks ========== - Comfortable PHP editing with VIM -2- on Tue, 23 Nov 2004 01:28:32 +0100 in Tobias Schlitt - Weblog I updated my .vimrc regarding the comments posted for my first entry about "Comfortable PHP editing with VIM". You can see and download it here. What I changed (in short): Added remappings for automatic completion of brackets and quotatio - 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... - Comfortable PHP editing with VIM -5- on Wed, 23 Aug 2006 16:39:00 +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:58:00 +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:44 +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 ======== - Rasmus at Fri, 12 Nov 2004 01:26:42 +0100 Try adding this to your vimrc: set dictionary-=/usr/share/funclist.txt dictionary+=/usr/share/funclist.txt set complete-=k complete+=k And grab http://lerdorf.com/funclist.txt and copy it to /usr/share Then hit Ctrl-N or Ctrl-P as you are typing a function name. Read up on vim's dictionary completion feature to learn more. - Jörn Horstmann at Fri, 12 Nov 2004 10:03:11 +0100 VIM is really a great editor! Note that you can use instead of ^M in your vimrc, this makes it easier to read or view in other applications. Here are some more mappings for automatically closing quotes and parentheses: inoremap { {<CR>}<C-O>O inoremap [ []<LEFT> inoremap ( ()<LEFT> inoremap " ""<LEFT> inoremap ' ''<LEFT> Hope you find this useful. - Toby at Fri, 12 Nov 2004 11:22:48 +0100 Rasmus, thanks a lot for your addition! Sounds really pretty useful! - Toby at Fri, 12 Nov 2004 11:25:24 +0100 Thanks! I always enjoyed that feature in other editors and wondered how to get that into VIM. :) Beside that, I cannot imagine, which character you meant instead of ^M. Maybe you could write me an email about that? - Jacques at Sat, 13 Nov 2004 00:41:12 +0100 Hi Rasmus, That function completion stuff is a gem :) I'm eventually getting my vim to behave better seeing that we have a vim zealot here at work and various tips I've started picking up from various sources. - Jon Wood at Sat, 13 Nov 2004 21:43:45 +0100 I've been playing with my .vimrc today (and thanks Toby for the starting point), and changed these to: inoremap { {}<Left> ... Which will place the cursor between them instead of having to move it manually. I'm lazy. I also discovered Cream [http://cream.sf.net], which is like Vim without relying so much on editing modes, which are easily the thing that annoy me most. It also supports defining code templates to be expanded be hitting x2. My .cream-user file is at http://www.jellybob.co.uk/~jon/cream.rc for the curious. - Toby at Mon, 15 Nov 2004 22:55:17 +0100 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.) - Josh at Fri, 27 May 2005 19:41:38 +0200 " Autocompletion using the TAB key (forward) " and SHIFT-TAB (backward) function InsertTabWrapper(direction) let col = col('.') - 1 if !col || getline('.')[col - 1] !~ '\k' return "\" elseif "backward" == a:direction return "\" else return "\" endif endfunction inoremap =InsertTabWrapper("forward") inoremap =InsertTabWrapper("backward") - Sérgio Carvalho at Mon, 20 Jun 2005 20:04:51 +0200 You might like to have a look at my PHP5 template VIM filetype plugin, at http://www.vim.org/scripts/script.php?script_id=1307 - Wolfgang Jacobs at Sat, 28 Jan 2006 11:22:08 +0100 Well I do not like general abbreviations in my .vimrc. So I done all that stuff in a special file called "php_abb.vim" located in my ~/.vim/ftplugin folder. It is sourced when editing php-files. So I also put: au! BufNewFile *.php :r ~/.vim/skeleton.php | :source ~/.vim/ftplugin/php_abb.vim au! BufNewFile *.phps :r ~/.vim/skeleton.php | :source ~/.vim/ftplugin/php_abb.vim au! BufNewFile *.php4 :r ~/.vim/skeleton.php | :source ~/.vim/ftplugin/php_abb.vim au! BufNewFile *.php5 :r ~/.vim/skeleton.php | :source ~/.vim/ftplugin/php_abb.vim au! BufNewFile *.php4 into the "augroup filedetect"-section of ~/.vim/filetype.vim and augroup phpstuff autocmd FileReadPost *.php :source ~/.vim/ftplugin/php_abb.vim autocmd FileReadPost *.php4 :source ~/.vim/ftplugin/php_abb.vim autocmd FileReadPost *.php5 :source ~/.vim/ftplugin/php_abb.vim autocmd FileReadPost *.phps :source ~/.vim/ftplugin/php_abb.vim autocmd FileReadPost *.inc :source ~/.vim/ftplugin/php_abb.vim augroup END into the same file. The abbreviations are just set while working on php then. I am doing a lot of other stuff with vim so I don't get bothered of these settings while writing mails or other non-php related things. Btw: Thank you for your nice work here! Yours, wolle - Toby at Sat, 28 Jan 2006 11:51:44 +0100 Hi! Please consider my more up2date blogentries anbout VIM (nr 4 is the most actual in the series): http://schlitt.info/applications/blog/index.php?serendipity%5Baction%5D=search&serendipity%5BsearchTerm%5D=vimrc :) Cheers! Toby - anonymous at Thu, 11 May 2006 23:08:28 +0200 Dead links on some of your a tags. - mp3 files search at Fri, 21 May 2010 10:46:34 +0200 Hello i also wrote a introduction to vim. More like a small cheat sheet. That incluse some tricks and covers other extension like DBext let you build queries (say you forgot the table name, field name ...) It has auto completation. - wheelchairs at Wed, 24 Nov 2010 08:48:41 +0100 I appreciate your post on Comfortable PHP editing with VIM, thanks for sharing the post, i would like to hear more about this in future - Ashesh at Wed, 02 Feb 2011 08:04:28 +0100 .vimrc is not more accessible. :-( - william johnson at Thu, 26 May 2011 02:41:29 +0200 I want to learn more about it and i also want to increase my speed... - Fran at Sat, 10 Dec 2011 18:44:11 +0100 Your .vimrc file link does not work anymore... :-(