When developing PHP apps I often want to run the current file and see the results. Sometimes I even want to save those results, or perhaps manipulate the results. So I wrote this little vim function to run my currently open PHP file and place the results in a new VIm buffer.
function! RunPHP () let filename = expand("%:p") let root = getcwd() exe 'cd %:p:h' exe 'enew' exe 'set buftype=nofile' exe 'setlocal noswapfile' exe 'r!/Applications/MAMP/bin/php/php5.3.13/bin/php ' . filename exe 'norm gg' exe 'cd ' . root endfunction
I also have some additional settings configured run add auto completion for PHP functions, check PHP syntax, and run the PHP script.
" PHP auto complete autocmd FileType php set omnifunc=phpcomplete#CompletePHP " Check PHP syntax map :!/Applications/MAMP/bin/php/php5.3.13/bin/php -l % " Run current PHP file and place output in new buffer map :call RunPHP()