Search, replace and go to

This section describes search-related commands from the Search menu and the editor window's popup menu:

* These items are available from the editor window's popup menu, or by using a keyboard shortcut (see the section called “Keybindings”).

Find

The Find dialog is used for finding text within the current document. The syntax for the "Use regular expressions" option is shown in Table 3.2, “Regular expressions”.

Figure 3.1. Find dialog

Find dialog

Find usage

Find usage searches all open files. If there is a selection, then it is used as the search text; otherwise the current word is used. The current word is either taken from the word nearest the edit cursor, or the word underneath the popup menu click position when the popup menu is used. The search results are shown in the Messages window.

Find in files

Find in files is a more powerful version of Find usage that searches all files in a certain directory using the Grep tool. The Grep tool must be correctly set in Preferences to the path of the system's Grep utility.

Replace

The Replace dialog has the same options for finding text as the Find dialog. There is also a "Replace in all files" option, which is used with the Replace All button to perform the replacement for all open files.

The "Use regular expressions" option applies both to the search string and to the replacement text; for the latter back references can be used - see the entry for '\n' in Table 3.2, “Regular expressions”.

Go to tag definition

If the current word is the name of a function and the file containing the function definition (a.k.a. function body) is open, Go to tag definition will switch to that file and go to the corresponding line number. The current word is either taken from the word nearest the edit cursor, or the word underneath the popup menu click position when the popup menu is used.

Go to tag declaration

Like Go to tag definition, but for a forward function declaration (a.k.a. function prototype) instead of a function definition.

Go to line

Go to a particular line number in the current file.

Regular expressions

You can use regular expressions in the Find and Replace dialogs by selecting the "Use regular expressions" check box. The syntax is POSIX-like, as described below in Table 3.2, “Regular expressions”.

Note

Searching backwards with regular expressions is not supported.

Table 3.2. Regular expressions

In a regular expression, the following characters are interpreted:
.Matches any character.
(This marks the start of a region for tagging a match.
)This marks the end of a tagged region.
\nWhere n is 1 through 9 refers to the first through ninth tagged region when replacing. For example, if the search string was Fred([1-9])XXX and the replace string was Sam\1YYY, when applied to Fred2XXX this would generate Sam2YYY.
\<This matches the start of a word.
\>This matches the end of a word.
\xThis allows you to use a character x that would otherwise have a special meaning. For example, \[ would be interpreted as [ and not as the start of a character set. Use \\ for a literal backslash.
[...]This indicates a set of characters, for example, [abc] means any of the characters a, b or c. You can also use ranges, for example [a-z] for any lower case character.
[^...]The complement of the characters in the set. For example, [^A-Za-z] means any character except an alphabetic character.
^This matches the start of a line (unless used inside a set, see above).
$This matches the end of a line.
*This matches 0 or more times. For example, Sa*m matches Sm, Sam, Saam, Saaam and so on.
+This matches 1 or more times. For example, Sa+m matches Sam, Saam, Saaam and so on.

Partial POSIX compatibility

Note that the POSIX '?' regular expression character for optional matching is not supported by the Find and Replace dialogs.