Thursday, February 15, 2018

Change only second match on a line...

Is there a way to change only the second (or any specific) instance of a
pattern on a line?

Sort of like how 's/old/new/' changes the first instance of "old" to
"new", but for the second (or any specific) instance.

Or does this involve changing the first instance of "old" twice and then
changing the first instance of the "new" pattern back to the "old" pattern?

Extrapolating the above sequence out to subsequent instances would be
more and more annoying.

I know that I can build a full RE that will match the first, second, and
subsequent instances and surrounding text but that seems cumbersome
compared to a tweak of "s/old/new/".



--
Grant. . . .
unix || die

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: