加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

vim – vi – 如何生成数字序列?

发布时间:2020-12-15 09:18:31 所属栏目:安全 来源:网络整理
导读:有没有办法在vi(m)中生成数字序列? 例如,从文件中的随机行(在vim中打开),例如Row-i到随机行,例如Row-j,其中Row- Row-j,是否有一种方法来生成从Row-i到Row-j的数字序列,从数字1开始到数字j-i 1,步长递增为1? 说我在文件中有以下几行。 this is line
有没有办法在vi(m)中生成数字序列?

例如,从文件中的随机行(在vim中打开),例如Row-i到随机行,例如Row-j,其中Row- Row-j,是否有一种方法来生成从Row-i到Row-j的数字序列,从数字1开始到数字j-i 1,步长递增为1?

说我在文件中有以下几行。

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,4,6,8,10,即具有步数2。

请注意:

这个SO post是相似的,但不一样。

用V(Shift-v)选择几行,然后输入命令:
:let i=1 | '<,'>g/^/ s//=i . " "/ | let i+=2

类型:help sub-replace-expression来阅读更多。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读