In your case, a simple regular expression is enough (and the best solution). However, in some other cases, recording a macro might be better.
There is a simple macro example at vim documentation, section 12.1, and further description at :help q
In a nutshell:
- Type
q
followed by a letter (the letter is the register
where the macro will be recorded).
- Do some commands, modify your text as needed, use all power of Vim.
- Move the cursor to the next line.
- Press
q
to stop recording.
To play a macro, press @
followed by the letter where the macro was recorded. To re-play the last macro, press @@
. Type a number before playing a macro to repeat it as many times as needed.
So, in your case, to transform the lines like this:
2 No route to specified transit network
{2, "No route to specified transit network"},
- Position your cursor at one of the lines.
- Press
qa
(the choice of register a
was arbitrary).
- Press exactly this (including quotes and spaces)
I{<esc>f cl, "<esc>A"},<esc>j
- Press
q
to stop recording.
- Press
100@a
and be happy watching the macro being played. :-)
I'll leave to the reader the explanation of each command from step 3. ;-)
Of course, this is not the only solution. You could have done the step 3 in many different ways.