实验要求
用 Vim 生成一个 20 行的有序列表,像这样——
line: 1, for ifanrx testing;
...
line: 20, for ifanrx testing;
实验结果
步骤解析
格式:键位操作
(补充解释说明)
i0<esc>
(进入 insert mode 插入模式,输入 “0”,然后按 esc 键回到 normal mode 普通模式)m1
(将当前光标位置标记为 1)qa
(开始 macro 宏录制,保存为 a)o
(新开一行,并进入插入模式)line: <esc>
(输入 “line: " 然后按 esc 回到普通模式)m2
(将当前光标位置标记为 2)- ```1`` (按下 `1 去到标记为 1 的光标位置,也就是我们刚刚输入 0 的那个地方)
<ctrl>a
( Ctrl + a 将光标下的数字加 1,0 -> 1)yiw
(复制光标下的整个单词)- ```2`` (去到标记为 2 的位置,也就是 “line: " 的右边)
p
(粘贴), for ifanrx testing;<esc>
(输入 “, for ifanrx testing;” 然后按 esc 键回到普通模式)q
(结束宏录制)20@a
(重复执行刚刚录制的宏)
关键知识点
标记光标位置
m{a-zA-Z}
Set mark {a-zA-Z} at cursor position (does not move the cursor, this is not a motion command).
宏录制
q{0-9a-zA-Z”}
Record typed characters into register {0-9a-zA-Z”} (uppercase to append). The ‘q’ command is disabled while executing a register, and it doesn’t work inside a mapping and |:normal|.