Desktop Tools and Development Environment Previous page   Next Page

Finding Text in Files

There are different ways to find text in files:

Finding Text in the Current File

Within the current file, select the text you want to find. From the Edit menu, select Find Selection. The next occurrence of that text is selected. Select Find Selection again (or Find Next) to continue finding more occurrences of the text.

To find the previous occurrence of selected text (find backwards) in the current file, select Find Previous from the Edit menu. The previous occurrence of the text is selected. Repeat to continue finding the previous occurrences of the text.

Finding and Replacing Text in the Current File

You can search for specified text within multiple files, and then replace the text within a file.

Finding Text.   To search for text in files, click the Find button Image of Find and Replace dialog box. in the Editor/Debugger toolbar, or select Edit -> Find and Replace. Complete the resulting Find & Replace dialog box.

The search begins at the current cursor position. MATLAB finds the text you specified and highlights it. To find another occurrence, click Find Next or Find Previous, or use the keyboard shortcuts F3 and Shift+F3 (or Command+F3 and Command+Shift+F3 with Macintosh key bindings).

MATLAB beeps when a search for Find Next reaches the end of the file, or when a search for Find Previous reaches the top of the file. If you have Wrap around selected, it continues searching after beeping.

Use F3 and Shift+F3 to continue finding the specified text even after closing the Find & Replace dialog box. You can go to another file and find the specified text in it.

Change the selection in the Look in field to search for the specified text in other MATLAB desktop tools.

Replacing Text.   After finding text using the Find & Replace dialog box, you can replace the text in the current file:

  1. In the Replace with field, type the text that is to replace the found text.
  2. Click Replace to replace the text currently selected, or click Replace All to replace all instances in the current file.
  1. The text is replaced. For Replace All, the number of instances that were replaced appears in the Editor/Debugger status bar.

  1. To save the changes to the file, select Save from the File menu.

You can repeat this for multiple files.

Function Alternative for Finding Text.   Use lookfor to search for the specified text in the first line of help for all M-files on the search path.

Finding Files or Text in Multiple Files

To find directories and filenames that include specified text, or whose contents contain specified text, use Edit -> Find Files. For details, see Finding Files and Content Within Files.


Previous page  Navigating in an M-File Incremental Search Next page

© 1994-2005 The MathWorks, Inc.