VIM:使用自定义函数作为shell的参数

VIM:使用自定义函数作为shell的参数,shell,vim,Shell,Vim,我在一个vim文件中有以下代码,它在编辑php文件时是自动来源的。但我不能让它工作 "PHP config if !exists("g:addPath") let g:addPath = 1 let $PATH=$PATH.';C:\Program Files\Mozilla Firefox' endif function! MakeThisUrl() let s:url='http://localhost/' let s:url=s:url. expand('%') r

我在一个vim文件中有以下代码,它在编辑php文件时是自动来源的。但我不能让它工作

"PHP config
if !exists("g:addPath")
  let g:addPath = 1
  let $PATH=$PATH.';C:\Program Files\Mozilla Firefox'
endif 

function! MakeThisUrl()
  let s:url='http://localhost/'
  let s:url=s:url. expand('%')
  return s:url
endfunction

function! MakeCustomUrl()
  let s:url='http://localhost/'
  let s:url=s:url. expand('%:p')
  return s:url
endfunction


map <F9>  :w<CR>:!firefox -new-tab MakeThisUrl()<CR>
map <F10>  :!firefox -new-tab call MakeCustomUrl()
imap <F9>  <Esc>:w<CR>:!firefox -new-tab MakeThisUrl()<CR><CR>
imap <F10>  <Esc>:!firefox -new-tab call MakeCustomUrl()
PHP配置 如果!存在(“g:addPath”) 设g:addPath=1 让$PATH=$PATH';C:\Program Files\Mozilla Firefox' 恩迪夫 函数!MakeThisUrl() 让我们:urlhttp://localhost/' 让s:url=s:url.expand(“%”) 返回s:url 端功能 函数!MakeCustomUrl() 让我们:urlhttp://localhost/' 让s:url=s:url.expand('%:p') 返回s:url 端功能 映射:w:!firefox-新建选项卡MakeThisUrl() 映射:!firefox-新选项卡调用MakeCustomUrl() imap:w:!firefox-新建选项卡MakeThisUrl() imap:!firefox-新选项卡调用MakeCustomUrl() 这个想法是让vim自动生成正确的URL,这样我就可以通过按下F9来测试代码。但是,我不能让它执行MakeThisUrl()和我得到的所有结果

:!firefox -new-tab MakeThisUrl() <CR><CR>
:!firefox-新建选项卡MakeThisUrl()
而不是

:!firefox -new-tab http://localhost/filename.php <CR><CR>
:!firefox-新建选项卡http://localhost/filename.php 
有什么办法让它工作吗? 提前谢谢

但是,我不能让它执行MakeThisUrl()和我得到的所有内容
:!firefox-新建选项卡MakeThisUrl()

这不起作用,因为命令的执行方式与键入的命令相同。请尝试以下操作:

map <F9>  :up<CR>:execute ":!firefox -new-tab ".MakeThisUrl()<CR>
map:up:execute:“!firefox-新建选项卡“.MakeThisUrl()
主要的变化是:使用它执行表达式求值产生的命令。表达式求值是在调用函数时进行的。在这里,它的结果与
“:!firefox-新建选项卡“
,它将作为
Ex
命令执行(以
开头的命令;对于
:execute
来说,前导的
是可选的)


另外,小改动/吹毛求疵:不用
:w
使用(或
:update
),它只在缓冲区被修改时写入缓冲区。

非常感谢,它工作得很好。没有考虑使用execute生成命令。感谢
update
提示,我将它应用到
au
上的其他文件上