Post

Vim increment number at irregular rows

vim increment number at irregular rows

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[{
    "payload": {
        "data": {
            "vlan_id": 27,
            ...
        }
    },
    "_response": 200,
    ...
    "_iteration": 0           <---
}, {
    "payload": {
        "data": {
            "vlan_id": 27,
       ...
        }
    },
    "_response": 400,
    ...
    "_iteration": 0.         <---

1
:let c=1 | g/_iteration/ s/\d\+/\=c/ | let c+=1

**Result’’

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[{
    "payload": {
        "data": {
            "vlan_id": 27,
            ...
        }
    },
    "_response": 200,
    ...
    "_iteration": 1
}, {
    "payload": {
        "data": {
            "vlan_id": 27,
       ...
        }
    },
    "_response": 400,
    ...
    "_iteration": 2

...

This post is licensed under CC BY 4.0 by the author.