搜索并替换为命令的结果

Search and replace with the result of a command

在vim中,我想搜索和替换一段文字。但是我想用命令的输出替换它。

给出的文本:

{ "_template": "foo" }
{ "_template": "foo" }

我想搜索并替换为:

{ "_id": "239c55fd-538e-485f-8588-83d9735b6819" }
{ "_id": "2ae9f49f-244c-47b0-8f0f-c6c46e860af3" }

后者是unix/linux命令的结果uuidgen

它看起来像 s:/"_template": "foo"/"_id": "<uuidgen>"/,但我不确定在 <uuidgen> 做什么。命令 uuidgen 只是一个示例,但它是一个不带参数且不需要传入任何标准输入的命令(例如 wc 左右)。

每个search/replace需要重新调用命令

vim 有可能吗?还是我应该改用 sed and/or awk?

嗯……

类似的东西?

:s/"_template": "foo"/\='"_id": "'.trim(system('uuidgen')).'"'

关键是:s-\=