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].*$
?
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
Another way to do this is with a global command and the normal command.
:g/"id":[0-9]/norm A,
The global command runs norm A,
on every line that matches "id":[0-9]
. norm A,
runs A,
in normal mode which is append a ,
at the end of the line.
Take a look at :help :global
and :h :normal
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With