| MATLAB® | ![]() |
| On this page… |
|---|
Finding Text in the Current File Finding and Replacing 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.
You can search for specified text within multiple files, and then replace the text within a file.
To search for text in files, click the Find button
in the Editor toolbar, or select Edit > Find and Replace. Complete the resulting Find Replace dialog box.

The search begins at the current cursor position. The Editor 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).
The MATLAB® software 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 Microsoft® desktop tools.
After finding text using the Find Replace dialog box, you can replace the text in the current file:
In the Replace with field, type the text that is to replace the found text.
Click Replace to replace the text currently selected, or click Replace All to replace all instances in the current file.
The text is replaced. For Replace All, the number of instances that were replaced appears in the Editor status bar.
To save the changes to the file, select Save from the File menu.
You can repeat this for multiple files.
Use lookfor to search for the specified text in the first line of help for all M-files on the search path.
To find directories and file names that include specified text, or whose contents contain specified text, use Edit > Find Files. For details, see Finding Files and Content Within Files.
With the incremental search feature, the cursor moves to the next or previous occurrence of the specified text in the current file. It is similar to the Emacs search feature. Incremental search is also available in the Command Window—see Incremental Search.
To use the incremental search feature in the Editor, follow these steps:
How you begin the incremental search depends on your setting for the Editor/Debugger key bindings preference and in which direction you want to search:
Press Ctrl+S to search forward or Ctrl+R to search backward for Emacs and Macintosh key bindings.
Press Ctrl+Shift+S to search forward or Ctrl+Shift+R to search backward for Windows® key bindings.
An incremental search field appears in the left side of the status bar of the current file window. F Inc Search means search Forward from the cursor. The field label is instead R Inc Search when you search backwards.

In the incremental search field, type the text you want to find. For example, type plot.
As you type the first letter, p, the first occurrence of that letter after the cursor is highlighted. In the example shown, the cursor is in the middle of line 2, so the first occurrence of p, the p in problem on line 2, is highlighted.

Incremental search is case sensitive for uppercase letters. In the above example, searching for uppercase P, would instead find the P in Prepare on line 3.
When you type the next letter in the term you are searching for, the first occurrence of the term becomes highlighted. In the example, when you add the letter l to the p so that the incremental search field now has pl, the pl in plot on line 8 is highlighted. When you add ot to the term in the incremental search field, the whole word plot in line 8 is highlighted.
If you mistype in the incremental search field, use the backspace key to remove the last letters and make corrections.
After finding the p, press Ctrl+W to highlight the rest of the word found, in this case plot, which also puts the complete word in incremental search field.
To find the next occurrence of plot in the file, press Ctrl+S. To find the previous occurrence of the text, press Ctrl+R.
If MATLAB beeps, it either means the search is at the end or beginning of the file, or it means that the text was not found.
When the text is not found, Failing appears in the incremental search field. Modify the search term in the incremental search field and try again. Use Ctrl+G to automatically remove characters back to the last successful search. For example, if plode fails, Ctrl+G removes the de from the search term because plo does exist in the file.
When at the end or beginning of the file, press Ctrl+S or Ctrl+R again to wrap to the beginning (or end) of the file and continue the search. Use Ctrl+G after a finding a string to clear the search and return the cursor to the starting point.
To end the incremental search, press Esc or Enter, or any other noncharacter or number key except Tab or backspace.
The incremental search field no longer appears in the status bar. The cursor is now located at the position where the string was last found.
If you press Ctrl+S or Ctrl+R after displaying the blank incremental search field, the search term from your previous incremental search appears in the field. Then the backspace key deletes the entire previous search term, rather than just the last letter.
![]() | Navigating in an M-File | Comparing Files and Directories | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |