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:
Auto completion of functions using <TAB>
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).
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 <CTRL>-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 <CR> missing in the <CTRL>-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!
Bash users (as I am) are used to get their commands automatically completed when hitting the <TAB> key after typing parts of a command. This works in VIM's command mode, too. Until now, you needed to remember that <CTRL>-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 <TAB>. Since the <TAB> 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 <TAB> not for indenting you can simply use <CTRL>-v + <TAB>.
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.
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/<CTRL>-v/<SHIFT>-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.
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.
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 <CTRL>-h and phpm will show you the prototype.
phpm is provided by Havard Eide and can be downloaded here. It needs PHP5.
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
* charsWhen 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.
If you liked this blog post or learned something, please consider using flattr to contribute back: .
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..
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!
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
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).
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.
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?
Link to commentSimply use CTRL-V + (/{/[/"/' to type only the opening part (as it's said in the article! :)
Link to commentThanks.. I swear the CTRL-v wasn't working before.. I was just getting a visual block. It works fine now though.
Link to comment
Hmm... wired... Maybe you were in command mode (ctrl-v then indicates creating a visual block)?
No matter, now it's working! :) Have fun! :)
When I use code temlates, e.g. =cla, I get * doubled from the 2nd string:
/**
* * class
* * @access
* * @package
* * @since
* */
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
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: <CR>*/<CR><LEFT>require_once '<RIGHT>;<LEFT><Left>
line 175:
E20: Mark not set
line 177:
E488: Trailing characters: <CR>*/<CR><LEFT>include_once '<Right>;<Left><Left>
line 181:
E492: Not an editor command: public<CR>*/<CR><LEFT>define ('<Right>, '<Right><Right>;<ESC>?',<CR>i
line 185:
E492: Not an editor command: {<CR><ESC>?/\*\*<CR>/ \* <CR>$i
line 189:
E492: Not an editor command: public<CR>* @param <CR>* @return void<CR>*/<CR><LEFT>public function
line 190:
te function _
line 193:
E492: Not an editor command: (<Right><CR>{<CR><ESC>?/\*\*<CR>/ \* <CR>$i
line 197:
E488: Trailing characters: <CR>*/<CR><LEFT>public $ = ;<ESC>?/\*\*<CR>/ \* <CR>$i
line 199:
E488: Trailing characters: <CR>*/<CR><LEFT>private $_ = ;<ESC>?/\*\*<CR>/ \*
line 251:
E488: Trailing characters: <CR>*/<CR><LEFT>public $ = ;<ESC>?/\*\*<CR>/ \* <CR>$i
line 253:
E488: Trailing characters: <CR>*/<CR><LEFT>private $_ = ;<ESC>?/\*\*<CR>/ \* <CR>$i
line 266:
E488: Trailing characters: '':<CR><CR>break;<CR>default:<CR><CR>break;<CR>}<Up><Up><Up><Up><Up><Up><Up><ESC>/)<CR>i
line 270:
E492: Not an editor command: {<CR><CR>}<Up><Up><Up><Up><Up><Up><ESC>/)<CR>i
Any ideas why?
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
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
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
Hey,
don't you wanna upload your .vimrc again? :-)
I would like it,
Chris
Please look here for the latest version:
http://www.schlitt.info/applications/blog/index.php?/archives/372-Comfortable-PHP-editing-with-VIM-4.html
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
Link to commentYou 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.
Link to commentoh, fast reply.. thanx :)
Link to comment
The full Php functions updated method:
# wget -qO - http://www.php.net/manual/en/indexes.php | grep '<dd class="indexentry">' | grep -oP '>(.*)\(\)<\/' | sed 's/><a href=".*>//g' | sed 's/><b>//g' | sed 's/()<\///g' > php-funclist.txt.new
# wc -l php-funclist.txt.new
# 5900
Note that VIP (containing the .vimrc) is now hosted on Github: http://github.com/tobyS/vip
Link to commentReal comfortable)))
Link to commentGreat stuff, thanks for all the tips. I was hoping that you had been cooking up some improvements using VIM 7s omnicomplete feature. My experience with it thus far has been mixed, as it adds some interesting completion for objects, functions, and support for ctags. But in some ways it lags behind simple keyword completion.
Link to commentYour link http://www.wiki.cc/php/Epc_phpm gives 404 error. :-(
Link to commentOutstanding piece of work you have done. This type of post is rarely found. This site has proved its metals in the way of giving extra ordinary information.
Link to commentyou probably have invested a lot of time in the procedure and the downtime is really impressive. What interests me is one thing further - how did you make those nice picture for the tutorial. It's really impressive.
Link to commentGreat write-up, I am a big believer in commenting on blogs to assist the weblog writers know that they’ve added one thing worthwhile to the world large net!Anyway, in my language, there aren’t a lot good source like this.
Link to commentFields with bold names are mandatory.
Comfortable PHP editing with VIM -3- - Tobias Schlitt - Weblog
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)
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
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-
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-
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
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
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.
Comparative potencies of opioids tramadol. Tramadol side affects. Tramadol.