Php 如何在gvim中编写用户定义的命令?

Php 如何在gvim中编写用户定义的命令?,php,vim,Php,Vim,我已经在WindowsXP中安装了wamp堆栈,在这样的步骤中运行PHP文件 打开Vim进行编辑 省省吧 在浏览器-Firefox中运行 我已经在我的_vimrc中将其映射为F8 在Vim的命令模式下,它将执行以下操作 在C:\BitNami\wampstack-5.4.24-0\apache2\htdocs\test中写入当前文件 将其命名为file1.php 打开http://localhost/test/file1.php 在Firefox中保持沉默 如何在Vim中编写用户定义的命令? 如

我已经在WindowsXP中安装了wamp堆栈,在这样的步骤中运行PHP文件

打开Vim进行编辑 省省吧 在浏览器-Firefox中运行 我已经在我的_vimrc中将其映射为F8

在Vim的命令模式下,它将执行以下操作

在C:\BitNami\wampstack-5.4.24-0\apache2\htdocs\test中写入当前文件 将其命名为file1.php 打开http://localhost/test/file1.php 在Firefox中保持沉默 如何在Vim中编写用户定义的命令? 如何修改?为什么目标没有实现http://localhost/test/ 添加fname? Vim不会将目标解析为正确的文件

function Runphp(fname)
    :cd  C:\BitNami\wampstack-5.4.24-0\apache2\htdocs\test
    :w!  fname
    :let target ="http://`localhost`/test/" . fname
    :silent  !"c:\Program Files\Mozilla Firefox\firefox.exe"  target
endfunction
command! -nargs=1  Runphp call Runphp(<f-args>)

Vim的评估规则与大多数编程语言不同。您需要使用:execute以计算变量;否则,它是字面意义上的;i、 Vim使用变量名本身作为参数

此外,特别是在需要使用转义函数时,否则带有特殊字符的文件名/命令将不起作用

函数参数需要在函数内用:sigil引用

最后,您不需要在函数中预先添加:to命令;只需以交互方式进入命令行模式

function Runphp(fname)
    cd  C:\BitNami\wampstack-5.4.24-0\apache2\htdocs\test
    execute 'w!' . fnameescape(a:fname)
    let target ="http://localhost/test/" . fname
    silent execute '!"c:\Program Files\Mozilla Firefox\firefox.exe"' shellescape(target, 1)
endfunction
command! -nargs=1  Runphp call Runphp(<f-args>)

:help:command告诉您有关在Vim中创建命令的所有知识。execute'w!'中出现错误。fname,我不知道如何修改它。当你只说错话的时候,我不知道如何帮助你。请尽可能准确和具体。
function Runphp(fname)
    :cd  C:\BitNami\wampstack-5.4.24-0\apache2\htdocs\test
    :w!  fname
    :let target ="http://`localhost`/test/" . fname
    :silent  !"c:\Program Files\Mozilla Firefox\firefox.exe"  target
endfunction
command! -nargs=1  Runphp call Runphp(<f-args>)
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
set number
set langmenu=en_US
set fileencodings=utf-8,gb2312,gbk,gb18030
set termencoding=utf-8
set encoding=prc
let $LANG = "en_US"
set nowrap
set guioptions+=b
set modifiable
set write
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
behave mswin
set diffexpr=MyDiff()
function MyDiff()
    let opt = '-a --binary '
    if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
    if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
    let arg1 = v:fname_in
    if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
    let arg2 = v:fname_new
    if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
    let arg3 = v:fname_out
    if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
    let eq = ''
    if $VIMRUNTIME =~ ' '
        if &sh =~ '\<cmd'
            let cmd = '""' . $VIMRUNTIME . '\diff"'
            let eq = '"'
        else
            let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
        endif
    else
        let cmd = $VIMRUNTIME . '\diff'
    endif
    silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction

function Runphp(fname)
    cd  C:\BitNami\wampstack-5.4.24-0\apache2\htdocs\test
    execute 'w!' . fnameescape(a:fname)
    let target ="http://localhost/test/" . filename
    silent execute '!"c:\Program Files\Mozilla Firefox\firefox.exe"' shellescape(target, 1)
endfunction
command! -nargs=1  Runphp call Runphp(<f-args>)
function Runphp(fname)
    cd  C:\BitNami\wampstack-5.4.24-0\apache2\htdocs\test
    execute 'w!' . fnameescape(a:fname)
    let target ="http://localhost/test/" . fname
    silent execute '!"c:\Program Files\Mozilla Firefox\firefox.exe"' shellescape(target, 1)
endfunction
command! -nargs=1  Runphp call Runphp(<f-args>)