【发布时间】:2012-04-11 19:37:54
【问题描述】:
有没有办法在 vi 或 Vim 中生成数字序列?
例如,对于任意范围的行 i 到 j(其中 i j)在一个在 Vim 中打开的文件,有没有办法从 i 行的第 1 行到第 1 行生成一个数字序列(j - i + 1) 在线j?
说,我在一个文件中有以下几行:
this is line #1
this is line #2
this is line #3
this is line #4
this is line #5
this is line #6
this is line #7
this is line #8
this is line #9
this is line #10
我想在第 4 行到第 8 行的数字序列前面加上数字 1 到 5。操作后生成的文件应如下所示:
this is line #1
this is line #2
this is line #3
1 this is line #4
2 this is line #5
3 this is line #6
4 this is line #7
5 this is line #8
this is line #9
this is line #10
如果可能,有没有办法为生成的序列使用不同的步长?例如,是否可以将 2 用作步长,使得生成的序列为 2、4、6、8 等?
注意:问题“How to add line numbers to range of lines in Vim?”提出了类似的问题,但不一样。
【问题讨论】:
标签: vim pattern-matching vi sequential