I frequently find myself trying to replace e.g. foo
with bar
and bar
with foo
in a buffer.
The way I usually do it is either:
- 3 query-replaces:
aaa -> @@@
,bbb -> aaa
,@@@ -> bbb
- give up on automation and just do the replacement by hand
I suppose that it is possible to get something working using the ,
syntax in query-replace-regexp
to test if the matched string is aaa
or bbb
. But the resulting syntax would be too cumbersome, so I never really tried it.
The thing is, given how common a task it is, I think there must be a better, single-step, way of doing it, either built-in or in an existing package. Is there?