vim 里插入列表编号
0x00
markdown 里的 Ordered Lists 语法是这样的:
1. First item
2. Second item
3. Third item
4. Fourth item
虽然以下写法也是允许的,并且渲染的结果是一样的:
1. First item
1. Second item
1. Third item
1. Fourth item
但在编写时,尽量使用前一种吧,特别是在需要经常翻阅的源文件,比如写在注释里的时候。
所以现在的问题是,在 vim 里怎样(在修改的时候,初次编写时是不需要的)快速输入这样的列表编号?
0x01
当然常想到的肯定是 nl、cat -n ,或者 :put =range... 这样的用法,但对于编辑已有文字段落时不是很合适。
经过搜索,对于一篇文档的的几行文字,可以使用以下的写法:
- 选中需要调整的若干行,在指定位置插入 0 和点,比如若干行开头
shift-v, I, 0.,或者若干行的某个位置ctrl-v, j/k..., I, 0.;或者把已有的替换成为ctrl-v, j/k..., r, 0,等等; - 再次选中这些新添加的 0,依次改成 1、2、…,
ctrl-v, j/k..., g, ctrl-a,完成。
比如:
在第 2 行和第 3 行之间插入了新的内容:
1. First item
2. Second item
2. Insert new item
3. Third item
4. Fourth item
先把行首数字更换成 0:
0. First item
0. Second item
0. Insert new item
0. Third item
0. Fourth item
选中这些 0 并修改:
1. First item
2. Second item
3. Insert new item
4. Third item
5. Fourth item
完成。