Using vim as a php editor

I’ve added this to my ~/.vimrc file. Now, when I click ctrl-M I get a php compile, and ctrl-L gives me a syntax check.

"ML 2011-09-05
:autocmd FileType php noremap  :w!:!/usr/bin/php %

:autocmd FileType php noremap  :!/usr/bin/php -l %"ML 2011-09-05

I’m also trying out this tip from – jj instead of ESC.

:imap jj


:set foldmethod=indent
(z looks a bit like a fold)
zr - remove fold
zm - more fold

Other tips:
Remove text highlighting after a search

” (two single quote characters) brings you to the previous position in the file.

Line numbers:
set number
set nonumber

80 column limit:
set colorcolumn=80
set cc=80

Viewing two parts of a long file by splitting the screen:

Remove all lines with a certain regex pattern:
(I use this to remove all dpm() left over from Drupal debugging:

This one is great. If you copy code from one place to another and need to have it re-indented in the new location, put your cursor on the opening brace { and do this:


This will re-indent everything within the block for you.


Edit 2012-02-02: OK. I have been having a hard time doing copy and paste in vim/gvim, so I have broken down at added MS Windows-style Ctrl-C and Ctrl-V support.
Added this to my .vimrc
source $VIMRUNTIME/mswin.vim

Posted in vim

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: