next up previous contents
Next: Foreign Languages and Foreign Up: The Basics Previous: Cutting and Pasting (Killing   Contents


Searching and Replacing

Searching for text is important all throughout the processing of writing, but it's also a useful way to navigate a document too, if you can think of words specific to certain areas of your text that will allow you to pinpoint it. Emacs provides a very powerful way to search your document, and several additional search and replace mechanisms of use to writers.

The one you'll use most frequently is called incremental searching. When you press C-s emacs will prompt you for what you want to search for. It will then search as you type from the cursor position to the end of the document. But as you continue typing it will add those letters to the search. An example is worth a thousand words. Let's say you're searching for the word ``iconoclastic'' in your document. Hit C-s and start typing ``i-c-o-.'' As you type ``i'' emacs will highlight the next word that starts with ``i,'' but as you type ``ico'' it will highlight the first word that starts with ``ico,'' building as you type until finally you've typed in the whole word and emacs is highlighting the next occurrence of the word ``iconoclastic.'' If that's the position in the buffer you want to skip to, press enter at this point, or C-g to remain where you were when you started the search. C-r performs an incremental search backwards from the cursor.

Type M-% to begin the query replace process. This is the equivalent of search and replace in other software. Emacs will ask you at each word if you'd like to replace that occurrence of the word or no, and you can answer yes, no, yes from now on, cancel, and so on.

One limitation of regular searches in documents that have been formatted (filled) is that if the two words are separated by a newline, the incremental search function won't find them. For these cases, use the word search command: M-s w. It will find a phrase regardless of punctuation or spaces between the words.

Figure 10: Searching and Replacing
\begin{figure}\begin{tabular}{lc}
Command/Function & Keystroke  \hline
Increm...
...ery replace &
M-\%  Word search forward & M-s w \\
\end{tabular}
\end{figure}


next up previous contents
Next: Foreign Languages and Foreign Up: The Basics Previous: Cutting and Pasting (Killing   Contents
Randall Wood 2011-03-31