转自 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
-
copy visincr.vba.gz,到自己的~/.vim/下。
-
gzip -d visincr.vba.gz解压解压。
-
在/.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