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
" http://stackoverflow.com/questions/5622236/run-php-file-from-within-vim
:autocmd FileType php noremap  :w!:!/usr/bin/php %

" http://weierophinney.net/matthew/archives/164-Vim-Productivity-Tips-for-PHP-Developers.html
:autocmd FileType php noremap  :!/usr/bin/php -l %"ML 2011-09-05

I’m also trying out this tip from http://weierophinney.net/matthew/archives/164-Vim-Productivity-Tips-for-PHP-Developers.html – jj instead of ESC.

:imap jj

Folding

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

Other tips:
Remove text highlighting after a search
:nohl

” (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:
:vsplit

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

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:

=i{

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

From: http://stackoverflow.com/questions/235839/how-do-i-indent-multiple-lines-quickly-in-vi

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

Advertisements
Posted in vim

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: