2017-08-09 170 views
3

嗨我想做一个VIM映射来运行脚本时,我按F2。 我很难得到正在用vim编辑的文件的完整路径到命令函数中。Vim命令和映射

nnoremap <F2> :! php /home/kbuczynski/diff_re.php fix <full file path here> flagArg 

任何想法?

回答

5

你可以得到的完整路径与当前的缓冲区:

expand('%:p') 

你的映射可能看起来像这样(你还需要使用execute功能):

function! CallPHP() 
    execute '!php /home/kbuczynski/diff_re.php fix '.expand('%:p').' flagArg' 
endfunction 
nnoremap <F2> :call CallPHP()<CR> 

Here是处理文件路径的一些很好的文档。

+0

是的,我可以看到这是工作,但它这样做出于某种原因 PHP /home/kbuczynski/diff_re.php解决扩大(“/家庭/ file.php”)flagArg 这会导致脚本不运行 –

+1

@ KrzysztofBuczynski,gotcha,我更新了我的回答 –

+1

非常感谢 正如预期的那样工作 –

3

如果您没有其他变量需要注入,则不需要:executeexpand()。您应该可以直接使用%:p

nnoremap <F2> :!php /home/kbuczynski/diff_re.php fix %:p flagArg<cr> 

如果你需要阅读flagArg别的地方,好了,那么你就需要:execute