Emacs23
By typing
^S
you will be prompted to enter the string to search for. With the
search string still active, typing
^S
again to search for the next occurrence of that string in the
current buffer.
Typing
M-%
(usually accomplished by
ESC-%
rather than
ALT-%
under Linux) will bring
up the same search function, but when you press
RETURN
after entering the search key, you will
be prompted for a replacement string. Type in the string that you wish to replace the search key
with and press
RETURN
. If the search string is found in the current buffer, you will be presented
with the options shown in Table 2-6.
The more complex search and replace feature is available by default, only from the prompt
and is not bound to a particular key combination. To access this feature, you need to type in the
name of the mode, which in this case is “
query-match-regex
”. The complete key sequence
for this is:
M-X query-replace-regex
This command brings up a similar series of prompts that allows you to search for regular
expressions in the current buffer and, using the same options shown in Table 2-5, replace them.
Emacs has an auto-completion option that you can use instead of typing the entire com-
mand shown above. By typing:
M-X que
Emacs will search through its listing of modes and complete as much of the request as it
can. If there is a conflict and there are one or more modes that begin with the phrase that you
Table2-6 Search and Replace Options
ActionCommand
y or SPACEReplace the string at the pointer with the replacement string and search for the next
occurrence.
n or DELLeave the string at the pointer as is and search for the next occurrence.
!Replace globally from the pointer forward in the buffer.
.Replace the string at the pointer and then exit search and replace mode.
^Move point back to previous match.
uUndo the previous replacement.
q or ENTERExit search and replace mode.
.Display help.