【发布时间】:2020-02-28 09:30:29
【问题描述】:
在我的 vim 配置中,我映射了 ,pt 以运行 phpunit 测试。
map <leader>pt :!clear && vendor/bin/phpunit % --testdox<cr>
但有时我想使用 phpunit --filter 运行特定测试
map <leader>pt :!clear && vendor/bin/phpunit --filter {FUNCTION_NAME_HERE} % --testdox<cr>
有没有办法在vim中自动填入函数名?
【问题讨论】:
-
让我试试@phd
-
@phd,很抱歉,我做不到。我用
map <leader>pg :!clear && vendor/bin/phpunit --filter expand('<sfile>') % --testdox<cr>更新了我的.vimrc,测试了它,结果是E498: no :source file name to substitute for "<sfile>" -
<sfile>仅适用于 VimScript。我猜你需要shellescape(matchstr(getline(search('function', 'bcnW')), 'function\s\+\zs\w\+'))或类似的东西。 -
谢谢@Matt,我很抱歉,但也没有用...
map <leader>pg :!clear && vendor/bin/phpunit --filter shellescape(matchstr(getline(search('function', 'bcnW')), 'function\s\+\zs\w\+')) % --testdox<cr> -
当然不是,因为整个 VimScript 语句被逐字传送到 shell,它对 VimScript 一无所知。如果这行得通,我会很开心。阅读
:h :execute作为入门。