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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With