在 vimscript 中,如何遍历当前文件中正则表达式的所有匹配项,然后为每个结果运行 shell 命令?
我认为这是一个开始,但我无法弄清楚如何将整个文件提供给它并获得每场比赛。
while search(ENTIRE_FILE, ".*{{\zs.*\ze}}", 'nw') > 0
system(do something with THIS_MATCH)
endwhile
Run Code Online (Sandbox Code Playgroud)
你可以用subtitute()
它来代替。例如...
call substitute(readfile(expand('%')), '.*{{\zs.*\ze}}',
\ '\=system("!dosomething ".submatch(1))', 'g')
Run Code Online (Sandbox Code Playgroud)