schlitt.info - php, photography and private stuff ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :Author: Tobias Schlitt :Date: Mon, 28 Jan 2013 09:16:14 +0100 :Revision: 2 :Copyright: CC by-nc-sa ==================================== Comfortable PHP Editing With VIM -8- ==================================== :Description: As promised, I'm explaining my new VIM setup in some more detail, staring with the collection of plugins I use by now to enhance my VIM experience. I already have some in mind which I need to try out, but I would be happy to know which additional plugins you can recommend in relation to PHP programming (and beyond). Please leave a comment! :Abstract: `As promised`__, I'm explaining `my new VIM setup`__ in some more detail, staring with the collection of plugins I use by now to enhance my VIM experience. I already have some in mind which I need to try out, but I would be happy to know which additional plugins you can recommend in relation to PHP programming (and beyond). Please leave a comment! __ /opensource/blog/0739_comfortable_php_editing_with_vim_7.html __ https://github.com/tobyS/toby.vim `As promised`__, I'm explaining `my new VIM setup`__ in some more detail, staring with the collection of plugins I use by now to enhance my VIM experience. I already have some in mind which I need to try out, but I would be happy to know which additional plugins you can recommend in relation to PHP programming (and beyond). Please leave a comment! __ /opensource/blog/0739_comfortable_php_editing_with_vim_7.html __ https://github.com/tobyS/toby.vim **TLDR**: - Vundle__ (plugin manager) - UltiSnips__ (TextMate like snippets, but better) - PDV__ (generate doc blocks) - Skeletons__ (new file templates) - Powerline__ (awesome ruler bar) - Syntastic__ (static code analysis results in VIM) - Solarized__ (awesome, readable color scheme) - Whitespacetrail__ (mark and remove trailing whitespaces) - Rename__ (rename edited files) - Easymotion__ (fancy motions) - `VIM Pasta`__ (adjust indent on paste) __ https://github.com/gmarik/vundle __ https://github.com/SirVer/ultisnips __ https://github.com/tobyS/pdv __ https://github.com/tobyS/skeletons.vim __ https://github.com/Lokaltog/vim-powerline __ https://github.com/scrooloose/syntastic __ https://github.com/altercation/vim-colors-solarized __ https://github.com/jakobwesthoff/whitespacetrail __ https://github.com/danro/rename.vim __ https://github.com/Lokaltog/vim-easymotion __ https://github.com/sickill/vim-pasta ------ Vundle ------ Vundle__ is a VIM plugin manager and builds the basis for the setup. It takes care of installing, updating, removing and including other VIM plugins (and itself). For that, it supports plugins located on Github__ or `vim.org`__. Using Vundle is as easy as adding some line like __ https://github.com/gmarik/vundle __ https://github.com __ http://www.vim.org :: Bundle "tobyS/skeletons.vim" to your ``.vimrc`` and running :: :BundleInstall inside your VIM. --------- UltiSnips --------- TextMate made the functionality provided by this tool popular: UltiSnips__ allows you to define small, re-usable text (or code) snippets that contain placeholders. These snippets can the be bound to autocomplete-functionality, reacting on certain trigger strings and a trigger key. When both occur in your typing, the corresponding snippet is inserted and you can jump through the placeholders, which might be already pre-configured with sensible defaults. __ https://github.com/gmarik/vundle For example, the following snippet:: public function ${1} (${2}) { ${3:return ${4};} } could be bound to ``pub``, automatically leaving you with a method stub and sensible jump marks (1. function name, 2. parameters, 3. statements with a return statement as its default. UltiSnip can even do more powerful stuff like obtaining its default values from scripts and so own. I originally had SnipMate__ as my snippet engine, but that one is sadly unmaintained since some time now and UltiSnip offered the functionality I needed to use it in PDV__ and Skeletons__ out of the box. __ https://github.com/msanders/snipmate.vim __ https://github.com/tobyS/pdv __ https://github.com/tobyS/skeletons.vim --- PDV --- PDV (phpDocumentor for VIM) allows you to generate doc blocks from your PHP code (classes, methods, attributes) and tries to *guess* as much information for you as possible, filling out sensible defaults. In this brand new version (which ships even with automated tests \o/) you can use Vmustache__ templates to define how your doc blocks should look like. That was pretty hard in the previous version. __ https://github.com/tobyS/vmustache Even better, the new version supports snippets out of the box, using UltiSnips__. What that means is that you can provide jump marks in your doc templates and pre-fill them with the values guessed by PDV. So __ https://github.com/SirVer/ultisnips :: /** * ${1:{{name}}} * * @var ${2:{{type}}{{^type}}mixed{{/type}}} */ Could be your template for attributes (thats the default snip template shipped with PDV). The first jump mark (1) will be pre-filled with the name of the property, you will most likely overwrite that. The second jump mark (2) is right after the ``@var``. If PDV was able to guess a type (by a default value in the code), it will have that value pre-filled. This raises the chance that you can just skip over it (e.g. for scalars). If PDV could not guess a type, it fills our ``mixed``, which you will most likely want to overwrite when tabbing on it. --------- Skeletons --------- My old VIM setup contained a little hack to paste some template text when I created a new PHP file (mainly the opening ```` for me), all coloring of your text vanishes and potential jump marks appear where you might want to go, alphabetically numbered. Just hit the corresponing key to jump to that place. TLDR; take a look at the Easymotion__ website for a video how that works. __ https://github.com/Lokaltog/vim-easymotion __ https://github.com/Lokaltog/vim-easymotion --------- Vim Pasta --------- Moving code around often requires you to adjust its indentation. For example if you extract code into a dedicated method to make code more readable. The Pasta__ plugin attempts to take this job over for you. __ https://github.com/sickill/vim-pasta .. Local Variables: mode: rst fill-column: 79 End: vim: et syn=rst tw=79 Trackbacks ========== Comments ======== - Toby at Mon, 28 Jan 2013 23:19:23 +0100 After a remark to my setup, I replaced ":Rename" with https://github.com/tpope/vim-eunuch, which provides the same command + some more cool shell commands. - Ilya at Tue, 29 Jan 2013 17:47:41 +0100 I think you need to add some imagess or/and videos. It will be cool. - Michael at Fri, 01 Feb 2013 07:49:08 +0100 Have fun coding like it's 1970. - Toby at Fri, 01 Feb 2013 07:51:53 +0100 Well, I do. :) I once tried migrating to an IDE last year, but failed after a month. IDEs are just not made for what I do the largest amount of my time when coding: Editing text. They are so bloody inefficient with that. - Samfrank at Sat, 06 Apr 2013 14:28:05 +0200 Lovely work! I'm definitely going to visit the blog frequently. I tried the ctags command and this does seem to do exactly the same thing. You're right on that :) VIM is pretty damn cool. will take a look at NERDTree later. - Juliet at Sat, 04 May 2013 07:45:43 +0200 Thanks for this information and keep up the good work in this website. Cheers!