# HG changeset patch # User Richard M. Stallman # Date 1038164866 0 # Node ID 2eca4c95c2bf81c79530245756c19fc8d924d725 # Parent af5c2643120c7f5f09351d36f175500f48f9a656 (Unconditional Replace): Explain how to replace two strings each with the other. diff -r af5c2643120c -r 2eca4c95c2bf man/search.texi --- a/man/search.texi Sun Nov 24 19:06:57 2002 +0000 +++ b/man/search.texi Sun Nov 24 19:07:46 2002 +0000 @@ -845,6 +845,18 @@ A numeric argument restricts replacement to matches that are surrounded by word boundaries. The argument's value doesn't matter. + What if you want to exchange @samp{x} and @samp{y}: replace every @samp{x} with a @samp{y} and vice versa? You can do it this way: + +@example +M-x query-replace @key{RET} x @key{RET} @@TEMP@@ @key{RET} +M-x query-replace @key{RET} y @key{RET} x @key{RET} +M-x query-replace @key{RET} @@TEMP@@ @key{RET} y @key{RET} +@end example + +@noindent +This works provided the string @samp{@@TEMP@@} does not appear +in your text. + @node Regexp Replace, Replacement and Case, Unconditional Replace, Replace @subsection Regexp Replacement