Advanced Search and Replace in GAUSS


You're probably familiar with the basic find-and-replace. However, large projects with many files across several directories, require a more powerful search tool.

The GAUSS Source Browser is the powerful search-and-replace tool you need. We'll discuss some ways you can use it to make your life easier, including:

  1. How to find all usages of a function or variable in a file with two clicks.
  2. How to perform searches across multiple files and directories.
  3. Advanced search options, such as how to find only variable assignments.
  4. How to replace search terms across files and directories.

How to View All Uses of a Variable or Function

If an output seems incorrect or is causing an error, you need a quick way to trace the progress of specific variables. GAUSS's Find Usages functionality does exactly that.

Find Usages Basics

As shown in the image below, right-click on the variable you want to search for and select Find Usages.

Find all uses of a GAUSS variable.

This will search our current file for every instance of our search variable and display them in the GAUSS Source Browser.

List of all uses of a variable in GAUSS.

As we can see in the above image, Find Usages has shown us:

  1. The name and full path of the file.
  2. The full line of code containing our search term, which:
    • Starts with the line number.
    • Highlights our search term.

We can double-click on a line in the Source Browser to open it in the GAUSS editor.

How to Search Across Directories

The Find Usages basics alone are great, but the GAUSS Source Browser has much more to offer.

How to Open the Source Browser

In addition to right-clicking and selecting Find Usages, the Source Browser can be opened two ways:

  1. Select View > Source Browser from the GAUSS main menu. Open GAUSS Source Browser
  2. Use the Ctrl+Shift+F (Command+Shift+F) keyboard shortcut.

The Search Tab

Advanced search and replace in GAUSS.

The Search Tab is the starting point for any search. It has three input boxes:

  1. Search for accepts your search query.
  2. File pattern allows you to restrict your search to specific file types.
    • The default search pattern is *.*, where * is a wildcard character that will match any character or characters.
    • You can add a comma-separated list of files, or file types to match. For example: *.gss, estimate.src.
    • Click the downward-pointing arrow at the end of the File pattern box to bring up a list of common GAUSS file extensions, such as *.gss,*.src,*.sdf,*.gau,*.prg.
  3. Directory specifies the location to search.

Using these tools together can help us quickly locate the information we're looking for. For, example, suppose we want to find uses of the GAUSS generalized method of moments procedure, gmmFit, in internal GAUSS source code.

We can achieve this by:

  1. Entering gmmFit in the Search for box.
  2. Entering /Users/Research/gauss/src as our Directory.
  3. Selecting the Search button.

We could also set the File pattern option to *.src to limit our search to .src files. However, we left the default option to search all files in this case.

Multi-file search in GAUSS.

Our search results show that the term gmmFit is used between 1 and 37 times in each of five files in the specified directory.

Advanced Search Options

The Advanced Tab

Advanced search and replace in GAUSS.

The Advanced Tab provides many useful options for further refining our search. We'll discuss some of the most helpful and less common options.

How to Find Variable Assignments

The Assignments checkbox allows us to restrict our search to only the instances when a variable is assigned to. Narrowing the list of uses to assignments only is invaluable when tracking down the cause of an incorrect value. Search for variable assignments only in GAUSS. The screenshot above shows our original Find Usages search after adding the Assignments filter.

References is the opposite of Assignments, returning instances where a variable is used, but not assigned to.

How to Search Subdirectories

By default, the Source Browser will search the directory that you specify and all subdirectories. Uncheck the Search Subdirs checkbox to restrict the search to the main search directory only.

How to Replace Across Directories

The Replace Tab

Replace across multiple files in GAUSS.

Executing a Replace Across Multiple Files

After we have completed our desired search, we can perform our replace by:

  1. Selecting the Replace tab in the Source Browser window.
  2. Entering the new term in the Replace box.
  3. Clicking the Replace button.

Advanced Multi-file Replace Options

The checkboxes at the start of each line of the search results allow you to quickly control which results are replaced.

Backup Original will create a copy of your files with a .bak file extension before making the replace. Since there is no undo option for replacements made to files not open in the editor, the .bak copies allow you to recover the original file if you make a mistake.

Overwrite Backup will copy over any pre-existing .bak files made by previous searches with Backup Original selected. If this option is unchecked, GAUSS will use .bak2, .bak3, etc if pre-existing .bak files are found.


After reading this post, you now know how to use the advanced search and replace tools in GAUSS to be more productive!

We have learned:

  1. How to quickly search your current file with Find Usages.
  2. How to find the exact code you need to see across multiple files and directories.
  3. How to find only variable assignments or variable references.
  4. How to replace search terms across files and directories.

2 thoughts on “Advanced Search and Replace in GAUSS

Leave a Reply

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy