有时我会写一些文本,其中部分文件是由外部程序生成的。例如,考虑包含以下内容的C源代码文件:
/*
* 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:...
) ,粘贴并运行它,等待命令完成,然后选择 'a!}sort -u
并粘贴并运行它。这是不优雅的,因为它只是半自动的,而我认为它可以完全自动化。我阅读了 vim 的在线帮助文档和相关内容,但看起来并不能满足我的需求。我的想法是将正确的命令(s)填充到 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>
*/
这怎么实现呢?
:@z
作为寄存器比^R
寄存器的“完成”要容易得多(描述起来也是如此)。+1 - sehennoremap
命令本身不会将光标移动到适当的行。稍作修改即可解决此问题:"zy$2j:@z<CR>
。 - Jens