vim 根据模板一行一行生成序列号

转自 https://vim.fandom.com/wiki/Making_a_list_of_numbers#

vim 根据模板一行一行生成序列号

第一种方式,直接使用vim中:命令

Making a list of numbers

[show]

:put =range(11,15)

The five lines are:

11

12

13

14

15
:put =map(range(1,150), 'printf(''%04d'', v:val)')

The results range from 0001 to 0150. The map() function replaces each value with the result of the expression, which must be given as a string (the double ‘’ presents a single apostrophe when inside an apostrophe-quoted string). In the expression, v:val represents each value from the list in the first argument.

Here is another example, using a loop rather than map():


一般是用单引号拼接,因为模板中有单引号,现在使用双引号拼接
 :for i in range(8001,8003) | put ='sed  '.i | endfor

Executing this command inserts the following after the current line:

sed  8001
sed  8002
sed  8003




如果模板中存在单引号,而双引号导致结束,需要将连接的改为双引号,但是需要转义,变为 :for i in range(8001,8003) | put =\"sed '\".i | endfor
sed '8001
sed '8002
sed '8003

比如替换

 :for i in range(8001,8003) 
 | put ='sed -i \"s/8001/'.i.'/g\" '.i.'/redis.conf' | endfor
sed -i "s/8001/8001/g" 8001/redis.conf
sed -i "s/8001/8002/g" 8002/redis.conf
sed -i "s/8001/8003/g" 8003/redis.conf

转载地址
https://stackoom.com/question/2ciUR/Vim%E6%8A%8A%E5%91%BD%E4%BB%A4%E4%B8%8D%E5%85%81%E8%AE%B8%E5%8F%8C%E5%BC%95%E5%8F%B7-%E5%9B%A0%E6%AD%A4%E6%B2%A1%E6%9C%89%E8%BD%AC%E4%B9%89%E5%BA%8F%E5%88%97

第二种方式,使用vim的插件visincr插件生成序列

这里是工作目录
whereis vim
在vim的官网下载,https://www.vim.org 官网下载 visincr.vba.gz

  1. copy visincr.vba.gz,到自己的~/.vim/下。
    
  2. gzip -d visincr.vba.gz解压解压。
    
  3. 在/.vim/下:
    

安装
vim visincr.vba
:so %
:q

vim hello.txt
i
1
复制6次
Y6p

1
1
1
1
1
1
1

进入列编辑模式
ctrl+v
选择到最后一行
G
生成命令
:I

1
2
3
4
5
6
7

进入列编辑模式
ctrl+v
G
shift+i
输入hello
esc esc

hello1
hello2
hello3
hello4
hello5
hello6
hello7
hello8
hello9
hello10
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值