开发者

Run PHP file from within vim

开发者 https://www.devze.com 2023-02-23 08:02 出处:网络
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 PH

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


You can use:

:!php %

% stands for the current document, and :! executes any shell command.

You can also create a shortcut for it.


I have this in my .vimrc

" set make command when editing php files
set makeprg=php\ -l\ %
set errorformat=%m\ in\ %f\ on\ line\ %l

and then I map to F7 (or whatever you want) with:

:map <F7> :make <CR>
0

精彩评论

暂无评论...
验证码 换一张
取 消