Often I find myself inverting quotes:
from double quotes ""
to single quotes ''
and
from single quotes ''
to double quotes ""
.
I know there is a way to switch single quotes to double quotes::%s/'\(\([^']*\)\)'/"\1"/g
And a way to switch double quotes to single quotes::%s/"\(\([^"]*\)\)"/'\1'/g
but how do I do both operations together without including the first swapped quotes in the 2nd swapping?
Typically, when you want to swap A
& B
like this, you need an intermediate step where you replace A
with something entirely different and very likely to be unique within the document, whether an unusual character or something longer and crazier like |x-monkeyz-x|
.
You can then convert all the Bs to As, and finally all the |x-monkeyz-x|
to Bs.
For example,
'
with !X!
"
with '
!X!
with "
This is better: Easiest way to swap occurrences of two strings in Vim?
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