Search code examples
vimviex

Append to line in vim matching regex


I have a json file that I ran a find and replace in using vim, however I forgot a , at the end of the line.

...
"id":41483
"someName":"someValue",
...

Using vim, how can I append a , to every line matching \"id\"\:[0-9].*$?


Solution

  • Try this. Match everything that has id followed by any character till the end. Replace it with the matching group (matched by parentheses) which in the replace segment is represented by \1.

    %s/\(id".*\)$/\1,/g