Master UltraEdit’s Flexible Search Functions

October 10, 2024
Master UltraEdit’s Flexible Search Functions

Introduction

Every editor has a more or less good search function to search for text, numbers and characters. UltraEdit has integrated so many flexible options for this functionality that it will warrant and extensive explanation; but it is a worthwhile investment as it provides the user with extremely powerful tools for his daily usage. We would like to describe the functionality in the following text and use various practical examples to show why the search functions of UltraEdit are considered so outstanding by many users.

Quick Find

Quick Find is the function that is intended for quick lookups and can be opened using the key combination Ctrl + F. This opens a small box in the top right-hand corner, which is helpful if the user wants to search quickly without using the large/normal search function.

Figure 1: Quick Find fly-out box

It is particularly practical that UltraEdit enters the word at the position of the cursor in the search field by default.

Note: The key combination Ctrl + F can be changed in the UltraEdit settings. To do this, go to the Key mapping category in the UltraEdit settings and select Quick find in the list. The existing key combinations are displayed in the right area and a new combination can be defined directly below.

Find and Replace dialog

The actual search is handled in UltraEdit via the Find and Replace dialog, which is displayed with 4 tabs at the top: Find, Replace, Find in Files and Replace in Files.

This dialog can be launched via the menu, the ribbon icons and various key shortcuts, whereby the desired tab is preselected depending on the key combination:

Command Shortcut Function
Find Alt + F3 Comprehensive search for strings
Replace Ctrl + R Replaces search results in Find
Find in files Ctrl + Shift + F Find functionality in a chosen files or directory
Replace in files Ctrl + Shift + R Replace functionality in a chosen files or directory

 

The figure below shows the Find and Replace dialog in its standard display, whereby the word located at the cursor is automatically transferred to the search field:

Figure 2: Find and replace dialog

The search parameters are as extensive as the user wants them to be. In the default setting, the dialog shows basic functions. Use the gear symbol at the bottom to open the advanced search options:

Figure 3: Find and replace dialog with its advanced options

Two further keyboard shortcuts are required to navigate through the search results:

  • F3 or Shift + F3: Find next result
  • Ctrl + F3: Find previous result

The In section defines the used search parameters, which includes current/all open files or the selected text. In addition to the options for searching for whole words, case sensitivity, and counting the number of matches found, there are many practical power functions that I have appreciated for many years and have fortunately found again in UltraEdit. This also has to do with editing source code, for example in C++ or in Delphi as well as in other languages. 

One feature I’ve used a lot in the past is the highlighting of all matches found. When I write source code, as in the following screenshot in Object Pascal/Delphi, and enable the option Highlight all items found, all hits found are highlighted in color, which gives me a better overview of where further adjustments may be necessary:

ultraedit find query settings options

Figure 4: Find option for highlighting all items found

I also find the option List lines containing string extremely useful, whereby a new result dialog with the string matches is displayed after the search. By double-clicking on a line, UltraEdit jumps directly to the respective line. This option is very similar to the Microsoft Word search function, for example, whose results navigation I really appreciate and I am all the more pleased that UltraEdit also makes this possible.

Regular expressions are also an important major topic in all kinds of searches. UltraEdit also supports them extensively and they will be described in more detail later in this text.

To conclude the Find function, let’s talk about the 3 button symbols above:

  • Circle with clock inside: shows a history of all previous search terms for possible reuse
  • Yellow star: allows to define favorites that can be loaded for quick reuse. The context menu contains the menu items Add to favorites, Edit favorites and Favorites – the last item contains the saved favorites in a selectable list
  • Green star and dot: can be selected as soon as the option Regular expressions is enabled and opens a list of regular expression options appropriate to the selected regular expression engine

Replace

If we move from the classic find function of text/code to the replace function, the basic functionality is retained, and in a simple sense is supplemented by a second string that replaces the search string. UltraEdit offers in the Replace tab the same basic functionality and extends it with the function buttons:

  • Replace: replaces the string from the “Find what” section with the string from the “Replace with” section (keeps the Find and Replace dialog permanently open)
  • Replace once: replaces the searched string from the “Find what” section with the string from the “Replace with” section once (closes the Find and Replace dialog afterwards)
  • Replace all: replaces all occurrences of the searched string from the “Find what” section with the string from the “Replace with” section (keeps the Find and Replace dialog permanently open)

Figure 5: Find and replace dialog with the Replace function opened

You will also notice that a small black icon button with two arrows has been added to the “Replace with” section, which conveniently swaps the two strings of the “Find what” and “Replace with” sections. It has happened to me many times that I wanted to undo a replaced string, for which the undo function can of course also be used. Depending on the text/code, however, it may make sense to simply swap the two sections and then replace them again.

Also relevant for the replace function and always very helpful for me is the option Preserve case. This power function causes UltraEdit to match the case of the replace string with the case of the found string with the condition of multiple rules:

  • if the word found is all lowercase, the replacement word will be all lowercase
  • if the word found is all UPPERCASE, the replacement word will be all UPPERCASE
  • if the word found is MixedCase, the replacement word will match the casing of the replacement word

We will illustrate this function with an example from the Delphi world. A corresponding click event is created for a button on a form and the procedure Button1Click is called as soon as the button is clicked. If we now enter “Button1Click” in the Find section and “ButtonActionClick” in the replace section, the following for all occurrences happens:

  • “button1click” will be replaced with ”buttonactionclick”
  • “BUTTON1CLICK“ will be replaced with ”BUTTONACTIONCLICK”
  • ”Button1Click“ will be replaced with ”ButtonActionClick”

Find/Replace in Files

Now that we have talked in detail about finding and replacing in the currently open file/document, we come to the supreme discipline, namely finding and replacing in complete files and directories.

This functionality is already known from various IDEs (Integrated Development Environments), such as Microsoft Visual Studio and Embarcadero RAD Studio, where it is used to search projects or entire project groups across multiple files, folders, and even drives.

UltraEdit’s professionalism is now emphasized by providing this powerful feature of IDEs in a text editor, and we will take a closer look at it below:

Figure 6: Find and replace dialog with the Find in Files function opened

What is immediately noticeable here is the adjusted search focus in the In section, where the default setting is the “Files listed” option – this searches the files located in the two edit fields below, “In files/types” and “Directory”. While the directory field can accept a directory either in text form, via the “Use active file path” button or via the browse button next to it, the upper field “In files/types” can be used to specify either individual files or wildcards. Multiple entries are separated by a semicolon and 3 typical examples might look like this:

  • *.pas;*.cpp
  • Testfile.txt;*.cpp;*.h
  • *.pas;TestForm.frm;*.dfm

In these examples, wildcards and named filenames are mixed, which UltraEdit can easily handle when the semicolon is used as a separator.

Further In section options are available for open files, favorite files (Application Menu -> Favorite Files) and project files – the latter searches all files within a currently open project. These three options ignore the edit fields “In files/types” and “Directory”, as these are only used with the “Files listed” option.

The Find button closes the Find and Replace dialog, the search is then performed and all results are displayed in the Output Window below. The respective files can be opened in the Output Window by double-clicking on the line with the file name. Anyone who is familiar with the Output Window will know that there are many more options available in a context menu via the right mouse button. These include collapsing/expanding the entire window content and copying the content to the clipboard.

Figure 7: Output Window with the results of the Find in Files search function

What is worth mentioning at this point, apart from the regular expressions (which we will come to at the end of this blog), are the interactive results.

When the Interactive results option is enabled, the Find in Files search will open a new Interactive results document. In this window all the Find in Files results are returned, but these results are immediately editable and the user doesn’t have to take intermediate steps to open matched files to edit the string that was searched for. This is effectively a window into the relevant portions of each matched file and the users may edit results individually as desired.

Figure 8: Interactive results window from the Find in Files function

If preferred and once the Interactive results document is opened, the user may switch to the Replace tab in the Find and Replace dialog. When focus is on the Interactive results document, the All open files option in the Replace dialog is dynamically changed to All results. If this option is selected, the user can use the replace operation interactively by pressing the Replace button, or uses Replace all to replace all matched strings in all files listed in the Interactive results document. When All results is selected in the Replace dialog, no other open files will be affected by the Replace all operation.

When direct editing of the results (either by typing or replace operations) are done, the user may close the Interactive results document. When the document is closed, a prompt appears asking whether the changes should be saved – changes would then be saved for all modified documents listed in the Interactive results document. This additional intermediate layer provides a clear way of keeping track of things, especially if there are many files that need to be changed.

The fourth major search function is Replace in Files, and here the Replace function is used in connection with listed files (names & wildcards as well as directories), favorite files or project files.

Figure 9: Find and replace dialog with the Replace in Files function opened

In the replace options, the user can include subdirectories, ignore certain hidden directories or file names/extensions and use the two options List changed files and Open matching files.

With the first option Open matching files is enabled, any files matching the specified parameters will be opened when the search completes. The second option List changed files instructs UltraEdit to list all the files that were modified in the Output Window. If enabled, each file change will be listed in the Output Window followed by the number of occurrences found and changed.

Regular expressions

Regular expressions have been widely used for many years and once you have understood the principle, you will never want to miss them again. In UltraEdit, the option to activate regular expressions is available in all 4 tabs of the Find and Replace dialog. Once activated, you can choose from 3 different expression types:

  • Perl: UltraEdit uses Perl style regular expressions based on the Boost C++ Libraries
  • UltraEdit: UltraEdit uses its own style regular expressions
  • Unix: UltraEdit uses Unix style regular expressions.

Regular expressions are search strings where certain characters (symbols) have a special meaning. The following symbols and associated functions exist in the original UltraEdit syntax:

Symbol Function
% Matches the start of line – this indicates the search string must be at the beginning of a line but does not include any line terminator characters in the resulting string selected
$ Matches the end of line – this indicates the search string must be at the end of line but does not include any line terminator characters in the resulting string selected
? Matches any single character except newline
* Matches any number of occurrences of any character except newline
+ Matches one or more of the preceding single character/character sets, where at least one occurrence of the character must be found
++ Matches the preceding single character/character set zero or more times
^b Matches a page break
^p Matches a newline (CR/LF) (paragraph) (DOS files)
^r Matches a newline (CR Only) (paragraph) (MAC files)
^n Matches a newline (LF Only) (paragraph) (UNIX files)
^t Matches a tab character
[xyz] Matches any characters between brackets (a character set)
[~xyz] Matches any characters not between brackets including newline characters (a negative character set)
^{A^}^{B^} Matches expression A or B
^ Overrides the following regular expression character
^(…^) Brackets or tags an expression to use in the replace command. A regular expression may have up to 9 tagged expressions, numbered according to their order in the regular expression.   

The corresponding replacement expression is ^x, for x in the range 1-9
Example:
If ^(h*o^) ^(f*s^) matches “hello folks”, ^2 ^1 would replace it with “folks hello”.

These symbols and associated functions result in many examples, some of which are described below to give you an idea of how they are used:

m?n matches “man”, “men”, “min” but not “moon”

t*t matches “test”, “tonight” and “tea time” (the “tea t” portion) but not “tea
time” (newline between “tea ” and “time”).

Te+st matches “test”, “teest”, “teeeest” etc. but does not match “tst”

[aeiou] matches every lowercase vowel

[,.?] matches a literal “,”, “.” or “?”

[0-9a-z] matches any digit, or lowercase letter

[~0-9] matches any character except a digit (~ means not the following)

 

The user can search for an expression A or B as follows:

“^{John^}^{Tom^}”

This will search for an occurrence of John or Tom – there should be nothing between the two expressions.

 

 The user can combine A or B and C or D in the same search as follows:

“^{John^}^{Tom^} ^{Smith^}^{Jones^}”

This will search for John or Tom followed by Smith or Jones.

 

Summary

UltraEdit offers flexible search and replace functions that work either for individual files/documents or complete directory structures. Countless options allow you to fine-tune the parameters and leave almost nothing to be desired. UltraEdit thus takes the step forward of providing much more powerful functions than many users are used from a text editor. As a result of these options, productivity is increased and search and replace is as powerful as the user works with this functionality – this blog provides the necessary know-how for this.

If you’re looking for a versatile text editor with powerful find and replace functionality, you can rely on UltraEdit. Download it now and try it for 30 days for free.

Try UltraEdit

 

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Recent Posts

Latest News

Subscribe to Our Newsletter