Run PHP file from within vim

前端 未结 3 2004
暖寄归人
暖寄归人 2020-12-29 13:58

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 call

3条回答
  •  爱一瞬间的悲伤
    2020-12-29 14:38

    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  :w!:!/usr/bin/php %
    

    Or (this doesn't check the filetype beware)

    :map  :w!:!/usr/bin/php %
    

    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

提交回复
热议问题