Run PHP file from within vim

前端 未结 3 1986
暖寄归人
暖寄归人 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:30

    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 讨论(0)
  • 2020-12-29 14:34

    You can use:

    :!php %
    

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

    You can also create a shortcut for it.

    0 讨论(0)
  • 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 <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

    0 讨论(0)
提交回复
热议问题