point, just as a forward search finds matches that begin after it.
The characters @kbd{C-y} and @kbd{C-w} can be used in incremental
-search to grab text from the buffer into the search string. This makes
-it convenient to search for another occurrence of text at point.
-@kbd{C-w} copies the word after point as part of the search string,
-advancing point over that word. Another @kbd{C-s} to repeat the search
-will then search for a string including that word. @kbd{C-y} is similar
-to @kbd{C-w} but copies all the rest of the current line into the search
-string. Both @kbd{C-y} and @kbd{C-w} convert the text they copy to
-lower case if the search is currently not case-sensitive; this is so the
-search remains case-insensitive.
+search to grab text from the buffer into the search string. This
+makes it convenient to search for another occurrence of text at point.
+@kbd{C-w} copies the character or word after point as part of the
+search string, advancing point over it. (The decision, whether to
+copy a character or a word, is heuristic.) Another @kbd{C-s} to
+repeat the search will then search for a string including that
+character or word.
+
+ @kbd{C-y} is similar to @kbd{C-w} but copies all the rest of the
+current line into the search string. Both @kbd{C-y} and @kbd{C-w}
+convert the text they copy to lower case if the search is currently
+not case-sensitive; this is so the search remains case-insensitive.
The character @kbd{M-y} copies text from the kill ring into the search
string. It uses the same text that @kbd{C-y} as a command would yank.
of the pattern and asks you whether to replace it.
The replace commands normally operate on the text from point to the
-end of the buffer; however, in Transient Mark mode, when the mark is
-active, they operate on the region. The replace commands all replace
-one string (or regexp) with one replacement string. It is possible to
-perform several replacements in parallel using the command
-@code{expand-region-abbrevs} (@pxref{Expanding Abbrevs}).
+end of the buffer; however, in Transient Mark mode (@pxref{Transient
+Mark}), when the mark is active, they operate on the region. The
+replace commands all replace one string (or regexp) with one
+replacement string. It is possible to perform several replacements in
+parallel using the command @code{expand-region-abbrevs}
+(@pxref{Expanding Abbrevs}).
@menu
* Unconditional Replace:: Replacing all matches for a string.
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
after each matching line.
@kindex RET @r{(Occur mode)}
+@kindex o @r{(Occur mode)}
+@kindex C-o @r{(Occur mode)}
The buffer @samp{*Occur*} containing the output serves as a menu for
-finding the occurrences in their original context. Click @kbd{Mouse-2}
-on an occurrence listed in @samp{*Occur*}, or position point there and
-type @key{RET}; this switches to the buffer that was searched and
-moves point to the original of the chosen occurrence.
+finding the occurrences in their original context. Click
+@kbd{Mouse-2} on an occurrence listed in @samp{*Occur*}, or position
+point there and type @key{RET}; this switches to the buffer that was
+searched and moves point to the original of the chosen occurrence.
+@kbd{o} and @kbd{C-o} display the match in another window; @kbd{C-o}
+does not select it.
@item M-x list-matching-lines
Synonym for @kbd{M-x occur}.
@item M-x multi-occur @key{RET} @var{buffers} @key{RET} @var{regexp} @key{RET}
-This function is just like `occur', except it is able to search
+This function is just like @code{occur}, except it is able to search
through multiple buffers.
@item M-x multi-occur-by-filename-regexp @key{RET} @var{bufregexp} @key{RET} @var{regexp} @key{RET}
-This function is similar to `multi-occur', except the buffers to
+This function is similar to @code{multi-occur}, except the buffers to
search are specified by a regexp on their filename.
@item M-x how-many @key{RET} @var{regexp} @key{RET}