GPS provides extensive search capabilities in different contexts. For example, you can search in the currently edited source file or in all source files belonging to the project, even those that are not currently open. You can also search in the project view (on the left side of the main GPS window).
All of these search contexts are merged into a single graphical window that you can open either through the Navigate ‣ Find or Replace... menu or the shortcut Ctrl-F.
By default, the search window is floating and appears as a dialog on top of GPS. Put it inside the multiple document interface for easier access by selecting the Window ‣ Floating menu and dropping the search window into a new location (for example, above the Project view). Selecting either option pops up a dialog on the screen similar to the following:
This dialog contains three fields:
Type the string or pattern to search for. GPS supports two modes, strings or regular expressions. Toggle between the two modes either by clicking the Options button and selecting the appropriate check box or by opening the combo box by clicking on the arrow on the right of the entry field.
The combo box provides a number of predefined patterns. The top two are empty patterns that automatically set the appropriate strings or regular expression mode. The other regular expressions are language-specific and match patterns such as Ada type definitions or C++ method declarations.
Contains the string to replace the occurrences of the pattern. The combo box provides a history of previously used replacement strings. If a regular expression is used for search, special escapes 1, 2 .. 9 in this field refer to the corresponding matching subexpressions; 0 refers to the complete matched string.
The context in which the search should occur.
GPS automatically selects the most appropriate context when you open the search dialog by looking at the component that currently has the focus. If several contexts are possible for one component (for example, the editor has Current_File, Files from Project, Files..., and Open Files), the last one you used is selected. In most contexts, the Scope option restricts the search to a set of language constructs. For example, use this to to avoid matching comments when you are only interested in actual code or to only search strings and comments, but not code.
Change the context to a different one by clicking on the arrow on the right, which displays the list of all possible contexts, including:
Project View
Search the Project view. An extra Scope box is displayed where you can specify the scope of your search, a set of: Projects, Directories, Files, Entities. Searching entities can take a long time since GPS must parse every file during the search.
Open Files
Search all files currently open in the source editor.
Files...
Search a specified set of files. An extra Files box is displayed where you specify the files using standard shell (Unix or Windows) regular expressions (such as *.ad? for all files ending with .ad and any trailing character). The directory specifies where the search starts and the Recursive search button whether subdirectories are also searched.
Files From Projects
Search all files from the current project, including files from project dependencies.
Files From Current Project
Search all files from the current project, defaulting to the root project if none. The currently selected project might be the one to which the source file belongs (if you are in an editor) or the selected project (if you are in the Project view).
Files From Runtime
Search all specification files from GNAT runtime library
Current File
Search the current source editor.
Project Browser
Search the Project browser (see The Project Browser).
Normally, GPS sets the default value for Look In that matches the currently selected window. For example, if you are in an editor and open the search dialog, the context is set to Current File. If the project view is the active window, the context is set to the Project view. Optionally, GPS can remember the last context that was set (see the preference Search ‣ Preserve Search Context). In that case, if an editor is selected, GPS remembers whether the last time you started a search from an editor you decided to search in (for example) Current File or Files From Project.
Finally, you can create key shortcuts (through the Edit ‣ Key Shortcuts menu, in the Search category) to open the search dialog and set the context to a specific value.
The second section in the dialog is a row of five buttons, used to start the search, or continue to the next occurrence, or set options:
Regexp
Toggles between strings and regular expressions. Or you can select the arrow to the right of the Search for: field. The grammar used by regular expressions is similar to the Perl and Python regular expressions grammar and is documented in the GNAT Pro run time file g-regpat.ads. To open it from GPS, use the open from project menu (File ‣ Open From Project...) and type g-regpat.ads.
Whole Word
Force the search engine to ignore substrings. For example, “sensitive” no longer matches “insensitive”.
Select on Match
Gives the focus to the editor containing the match. If not selected, the focus remains on the search window. If so, press Enter to search for the next occurrence.
Close on Match
This button only appears if the search window is floating. If pressed, the search window is automatically closed when an occurrence of the search string is found.
Case Sensitive Search
By default, patterns are case insensitive (upper-case letters and lower-case letters are considered equivalent). Change this behavior by clicking this check box.
Case Preserving Replace
When this is checked, replacements preserve casing. Three casings are detected and preserved: all lower, all UPPER, and Mixed_Case (where the first character of each word is capitalized). When the replacement pattern is not all lower case, replacement is never case-preserving; the original casing of the replacement pattern is used.
Press the Find or Previous button to perform an interactive search, which stops as soon as one occurrence of the pattern is found. At that point, the Find button is renamed to Next, which you press (or type the equivalent shortcut Ctrl-N) to go to the next occurrence.
The Find all button starts a search for all occurrences and puts the results in a view called Locations view, see The Locations View.
The Replace and Replace & Find buttons are grayed out if no occurence of the pattern is found. To enable them, start a search, for example by pressing the Find button. Pressing Replace replaces the current occurrence (grays out the two buttons) and Replace & Find replaces the occurrence and jumps to the next one, if any. If you do not want to replace the current occurence, jump to the next one by pressing Next.
The Repl all button replaces all occurences found. By default, a popup is displayed asking for confirmation. You can disable this popup by either checking the box Do not ask this question again or going to the Search panel of the preferences pages and unchecking Confirmation for Replace all.
Like most GPS components, the search window is under control of the multiple document interface and can be integrated into the main GPS window instead of being an external window. To do this, open the Window ‣ Search menu in the list at the bottom of the menu, and either select Window ‣ Floating or Window ‣ Docked.
If you save the desktop (File ‣ Save More ‣ Desktop), GPS automatically reopens the search dialog in its new place when it is next started.