Tutorial: Searching

Index of All Documentation » Wing Tutorial »

Wing provides several different interfaces for searching your code. Which you use depends on your task.

Toolbar Search

A quick way to search through the current editor is to enter your search string in the area provided in the toolbar:


If you enter only lower case the search will be case-insensitive. Entering one or more upper-case letter causes the search to become case-sensitive.

Try this now in example1.py: Type GetItem in the toolbar search area and Wing will immediately, starting with the first letter typed, search for matching text in the editor. Press the Enter key to move on to the next match, wrapping around to the top of the file if necessary.

Toolbar-based searches always go forward (downward) in the file from the current cursor position.

Keyboard-driven Search

If you prefer a more powerful search interface using the keyboard only, try the key bindings for the items in the Mini-search sub-menu of the Edit menu (the bindings vary by keyboard personality). This feature is not available in Wing 101. From here, you can initiate searching forward and backward in the current editor, optionally using the current selection in the editor as the search string or using regular expression matching. You can also initiate replace operations.

Try this in the example1.py file: If using the default editor mode, press the Ctrl-U. For others, refer to the Mini-search group in the Edit menu.

This will display an entry area at the bottom of the IDE window and will place focus there:


Continue by typing G, then e, then t. Notice how Wing searches incrementally with each keypress. This lets you type only as much as you need to find the source code you are looking for.

While the mini-search area is still active, try pressing the same key combination you used to display it again and Wing will search for the next matching occurrence. Note that if no match is found Failed Search will be displayed. However, pressing the mini search key combination again will wrap around and start searching again at the top of the file, if there are any matches.

As in toolbar search, typing lower case letters results in case-insensitive search, and using one or more upper case letters results in case-sensitive search.

Search direction can be changed during searching by pressing the key bindings assigned to forward and backward mini-search. You can exit from the search by pressing the Esc key or Ctrl-G.

The regular expression based search options found in the Mini-search menu group work similarly but expect regular expressions for the search criteria (see below).

Keyboard-driven mini-replace works similarly, except that you will be presented with two entry areas, one for your search string and one for the replace string. Use Query/Replace to be prompted for Y and N for each replace location, and Replace String to replace all matches globally in the file.

Wing adjusts some details of how mini-search behaves according to keyboard personality. For example, in emacs mode Ctrl-G will cancel the search and in vi mode the search is always case sensitive, as in VI/VIM.

Search Tool

The Search tool provides a familiar GUI-based search and replace tool for operating on the current editor. Key bindings for operations on this tool are given in the Search and Replace group in the Edit menu.


Searches may span the whole file or be constrained to the current selection, can be case sensitive or insensitive, and may optionally be constrained to matching only whole words.

By default, searching is incremental while you type your search string. To disable this, uncheck Incremental in the Options menu.


When the Show Replace item in Options is activated, Wing will show an area for entering a replace string and add Replace and Replace All buttons to the Search tool:


Try replacing example1.py with search string PrintAs and replace string OutputAs.

Select the first result match and then Replace repeatedly. One search match will be replaced at a time. Search will occur again after each replace automatically unless you turn off the Find After Replace option. Changes can be undone in the editor, one at a time. Do this now to avoid saving this replace operation.

Next, try Replace All instead. Wing will simply replace all occurrences in the file at the same time. When this is done, a single undo in the editor will cancel the entire replace operation.

Wildcard Searching

By default, Wing searches for straight text matches on the strings you type. In Wing Pro and Wing Personal, wildcard and regular expression searching are also available in the Options menu.

The easier one of these to learn is wildcard searching, which allows you to specify a search string that contains * to match anything, ? to match a single character, or ranges of characters specified within [ and ] to match any of the specified characters. This is the same syntax supported by the Python glob module and is described in more detail in the Wildcard Search Syntax manual page.

Try a wildcard search now by selecting Wild Card from the Options menu and making sure example1.py is your current editor. Set the search string to PrintAs*(. This should display match all occurrences of the string PrintAs, followed by zero or more characters, followed by (:


Also try searching on PrintAs*[A-Z]( with the Case Sensitive search option turned on. This matches all strings starting with PrintAs followed by zero or more characters, followed by any capital letter from A to Z, followed by (.

Finally, try PrintAsT???, which will match any string starting with PrintAsT followed by any three characters.

Regular Expression Search

In Wing Pro and Wing Personal, regular expressions can also be used for searching. These are most useful for complicated search tasks, such as finding all calls to a particular function that occur as part of an assignment statement.

For example, open\(newscache( )?,.*\) matches only calls to the function open where the first argument is named newscache and there are at least two parameters. If you try this with example1.py, you should get exactly one search match:


In this mode, the replace string can reference regex match groups with , , etc, as in the Python re.sub() call.

The details of regular expression syntax and usage can be very complicated, so this tutorial does not cover them. For that, see the Regular Expression Syntax documentation in the Python manual.

Search in Files Tool

The Search in Files tool in Wing Pro and Wing Personal is the most powerful search option available in Wing. It supports multi-file batch search of the disk, project, open editors, or other sets of files. It can also search using wildcards and can do regular expression based search/replace.


Before worrying about the details, try a simple batch search on the example1.py file. Select Current File from the Look in selector on the Search in Files tool. Then enter PrintAs into the search area.

Wing will start searching immediately, restarting the search whenever you alter the search string or make other changes that affect the result set. When you are done, you should see results like those shown in the screen shot above. Click on the first result line to select it. This will also display example1.py with the corresponding search match highlighted.

You can use the forward/backward arrows in the Search in Files tool to traverse your results.

File Filters

Next, change the Look in selector to All Files in Project and change your search string to HTML. This works the same way as searching a single file, but lists the results for all files in your project. You can also search all currently open files in this way.

In many cases, searching is more useful if constrained to a subset of files in your projects such as only Python files. This can be done with by selecting Python Files in the Filter selector. You can also define your own file filters using the Create/Edit Filters... item in the Filter selector. This will display the Files > File Types > File Filters preference:


Each file filter has a name and a list of include and exclude specifications. Each of these specifications can be applied to the file name, directory name, or the file's MIME type. A simple example would be to specify *.pas wildcard for matching Pascal files by name, or using the text/html mime type for all HTML files.

Searching Disk

Wing can also search directly on disk. Try this by typing a directory path in the Look in area. Assuming you haven't changed the search string, this should search for HTML in all text files in that directory.

Disk search can be recursive, in which case Wing searches all sub-directories as well. This is done by selecting a directory in the Look in scope selector and checking Recursive Directory Search in the Options menu.

You can alter the format of the result list with the Show Line Numbers item and Result File Name group in the Options menu, which contains several other search options as well.

Note that searching Project Files is usually faster than searching a directory structure because the set of files is precomputed and thus the search only needs to look in the files and not spend time discovering them.

Multi-File Replace

When working with multiple files in the result set, Wing opens each changed file into an editor, whether or not it is already open. This allows you to undo changes by not saving files or by issuing Undo within each editor.

If you check Replace Operates on Disk in the Options menu within the Search in Files tool, Wing will change files directly on disk instead of opening editors into the IDE. This can be much faster but is not recommended unless you have a revision control system that can get you out of hot water if mistakes are made.

Note that even when operating directly on disk, Wing will replace changes in already-open editors only within the IDE. This avoids creating two versions of a file if there are already edits in the IDE's copy. We recommend selecting Save All from the file menu immediately after each replace operation. This avoids losing parts of a replace, resulting in inconsistent application of a replace operation to the files in your source base.