Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run PHP file from within vim

Tags:

php

vim

Is it possibly to run a PHP file from within vim? What im trying to do here is having a shortcut so whenever I need to run the file I'm editing to skip exiting vim and calling the PHP interpreter manually

like image 383
afarazit Avatar asked Apr 11 '11 13:04

afarazit


1 Answers

Yes! It's possible to do what you want. Both running PHP from within vim, and creating a shortcut.

Matthew Weier O'Phinney writes:

Probably the most useful thing I've done as a PHP developer is to add mappings to run the current file through (a) the PHP interpreter (using Ctrl-M), and (b) the PHP interpreter's linter (using Ctrl-L).

Vim Productivity Tips for PHP Developers

Example:

:autocmd FileType php noremap <C-M> :w!<CR>:!/usr/bin/php %<CR>

Or (this doesn't check the filetype beware)

:map <C-M> :w!<CR>:!/usr/bin/php %<CR>

Joe 'Zonker' Brockmeier writes:

Vim also allows you to execute a command directly from the editor, without needing to drop to a shell, by using bang (!) followed by the command to be run. For instance, if you're editing a file in Vim and want to find out how many words are in the file, run

:! wc %

Vim tips: Working with external commands

like image 177
Peter Lindqvist Avatar answered Oct 22 '22 21:10

Peter Lindqvist