我有时会发现自己正在编写文本,其中部分文件是由外部程序生成的。例如,考虑包含vim:执行光标后的其余行作为vim命令
/*
* To regenerate the following data, place the cursor at the beginning
* of the next line after this comment, then run
* ma:r!find /foo -name '*.in' | xargs whatever | some complicated processing
* and merge the result with
* 'a!}sort -u
*/
some
generated
stuff
here
我最终使用鼠标来选择第一命令(ma:...
),粘贴&运行它C源文件,等待命令完成,选择'a!}sort -u
并粘贴&运行它。这是不雅的,因为它只是半自动的,我认为它可以是全自动的。我阅读:execute
和朋友的vim在线帮助,但它看起来像没有做我想做的事。我正在考虑用适当的命令填充vim寄存器,然后执行寄存器内容。在线:help registers
到目前为止没有给出线索。
理想的情况下,新的评论会说像
/*
* To regenerate the following data, place the cursor on the 'j' on the
* next line in this comment, then execute it with <SHORT-MAGIC-VIM-INCANTATION>
* jjma:r!find /foo -name '*.in' | xargs whatever | ...<CR>'a!}sort -u<CR>
*/
如何才能实现这一目标?
哦aha。':@ z'用于寄存器比'^ R'寄存器'完成'更容易(也可以描述)+1 – sehe
'nnoremap'不会将光标移动到适当的行。修改修复了这个问题:'“zy $ 2j:@z'。 –
Jens