2

是否可以像这样搜索模式some_name{number}::例如 r001。然后将每个搜索结果编号递增 1。例如对于这样的输入:

r001
...
r001
...
r001
...

所需的输出将是:

r002
... 
r003
...
r004
4

1 回答 1

3

以下将用从 2 开始的递增数字替换整个文件中的每个数字。

let i=2|g/\v\d+$/s//\=i/|let i=i+1

输出

r2
...
r3
...
r4
...

分解

let i=2     : Initializes variable i to 2
g/\v\d+$/   : a global command to search for numbers at the end of lines
s//\=i/     : a substitute command to replace the search matches with 
              the contents of i
let i=i+1   : increment i for the next match

剩下要做的就是合并用零填充的命令: Vim:用字符填充行

于 2013-07-30T05:57:36.567 回答