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 in one or more open documents.

Figure 3.1. Find dialog

Find dialog


Matching options

The syntax for the Use regular expressions option is shown in Table 3.2, “Regular expressions”.

The Use escape sequences option will transform any escaped characters into their UTF-8 equivalent. For example, \t will be transformed into a tab character. Other recognised symbols are: \\, \n, \r, \uXXXX (Unicode chararacters).

Find all

To find all matches, click on the Find All expander. This will reveal several options:

  • In Document

  • In Session

  • Mark

Find All In Document will show a list of matching lines in the current document in the Messages tab of the Message Window. Find All In Session does the same for all open documents.

Mark will set markers for all matching lines in the current document, if the Markers margin is visible. If not, the background colour of matching lines will be highlighted. Markers and highlighting can be removed by selecting the Remove Markers command from the Document menu.

Find usage

Find usage searches all open files. It is similar to the Find All In Session Find dialog command.

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 tab of the Message 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. GNU Grep is recommended.

Figure 3.2. Find in files dialog

Find in files dialog


The Extra options field is used to pass any additional arguments to the grep tool.

Filtering out version control files

When using the Recurse in subfolders option with a directory that's under version control, you can set the Extra options field to use grep's --exclude flag to filter out filenames.

SVN Example: --exclude=*.svn-base

Note

The GNU Grep project added support for excluding directories, using the --exclude-dir flag. At the time of writing (April 2007) this is unreleased outside of version control. Check your Grep manual to see if your version supports it.

Example: --exclude-dir=.* --exclude-dir=CVS

Replace

The Replace dialog is used for replacing text in one or more open documents.

Figure 3.3. Replace dialog

Replace dialog


The Replace dialog has the same options for matching text as the Find dialog. See the section called “Matching options”.

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”.

Replace all

To replace several matches, click on the Replace All expander. This will reveal several options:

  • In Document

  • In Session

  • In Selection

Replace All In Document will replace all matching text in the current document. Replace All In Session does the same for all open documents. Replace All In Selection will replace all matching text in the current selection of the current document.

Go to tag definition

If the current word is the name of a tag definition (like a function body) and the file containing the tag definition is open, this command 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 declaration such as a function prototype or extern declaration instead of a function body.

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.