【发布时间】:2021-09-21 01:43:41
【问题描述】:
我在 Vim 中查看(和编辑)的纯文本文件中有以下段落:
The synthesis and secretion of estrogens is stimulated by follicle-stimulating hormone (FSH), which is, in turn, controlled by the hypothalamic gonadotropin releasing hormone (GnRH). High levels of estrogens suppress the release of GnRH (bar) providing a negative-feedback control of hormone levels.
我正在用这个文本文件中的文本创建完形填空删除抽认卡(即填写空白问题),然后将其提供给我编写的自制抽认卡程序。我的完形填空删除格式如下:
The synthesis and secretion of [estrogens] is stimulated by [follicle-stimulating hormone]
这将产生两个抽认卡(当我的抽认卡程序解析文本文件时):
The synthesis and secretion of [...] is stimulated by follicle-stimulating hormone
The synthesis and secretion of [estrogens] is stimulated by [...]
我想使用 Vim 自动创建这些抽认卡。手动选项是在每个完形填空删除的开头写一个“[”,最后写一个“]”,但这很乏味,我想使用 Vim 的自动化功能。理想情况下,我希望能够:
- 选择要填空的文本区域
- 对此文本执行宏
这个宏会:
- 在选择前添加“[”
- 将“]”附加到所选内容
然后退出。
我将如何使用 Vim 实现这一点?当我尝试在可视选择模式下使用 Ctrl-R 时,它似乎不起作用。
基本上,我想做的替换是:
:%s/(CONTENT OF VISUAL SELECT)/[(CONTENT OF VISUAL SELECT)]/g
【问题讨论】:
标签: vim