Chapter 8.  Tools and Utilities

This chapter describes the tools and utilities provided by SlickEdit Core that help while coding.

Find and Replace

SlickEdit® Core provides several different ways to search and replace:

  • For the fastest method of searching and replacing, use Quick Search and Quick Replace (see Quick Search and Replace below).

  • To find and replace text "on the fly," or, as you type, use incremental searching (see Incremental Searching below).

  • If you are more comfortable with keystrokes, you may prefer command line searching with the find and replace commands (see Find and Replace Commands).

  • Use the Find and Replace view if you prefer working within an interface (see Find and Replace View).

  • To search for symbols, use the Find Symbol view (see Find Symbol View).

Both the Find and Replace view and command line searching provide the same search and replace options for single or multiple files, and for searching and replacing text, wildcards and regular expressions, so you can choose which method works best for you.

This section also includes the topics Find and Replace with Regular Expressions, Undoing/Redoing Replacements, and Match Highlighting.

Default Search Options

The behavior for all of the search mechanisms in SlickEdit® Core is controlled by the Search Options located in the Options dialog (Window → SlickEdit Preferences → Editing → Search). The options specified here are used each time a search is performed, except for the Find and Replace View, which has controls to override these settings.

The value of the settings in the Options dialog are used to initialize the corresponding controls in the Find and Replace view. Once the value is changed in the view it is remembered and used the next time the Find and Replace view is launched. So changing a value in the Search Options may not have any effect on the Find and Replace view. Changing a setting in the Find and Replace view will not change the settings in the Search Options. See Search Options for more information.

Quick Search and Replace

Quick Search

The fastest way to search is by using Quick Search. Quick Search looks through the current buffer for the word or selection at the cursor. You can find the next occurrence of a search item by selecting a string in an existing buffer or Search Results window, then selecting Quick Search from the right-click menu (or by using the quick_search command). The commands find_next (Edit → Find Next or Ctrl+G) and find_prev (Edit → Find Previous or Ctrl+Shift+G) will find the next and previous instances of the item, respectively. Quick Search always uses the default search options (see Search Options.).

Quick Replace

Quick Replace gets the current word or selection at the cursor, prompts for replacement text on the command line, then highlights each occurrence of the word and prompts if you want to replace the text. Quick Replace always uses the default search options (see Search Options).

To use Quick Replace, right-click on any word or selection and select Quick Replace (or use the quick_replace command).

The quick_replace command has a command line alias, qr. The qr command takes the replace string as an argument. For example, if the cursor is on the word "cat," the command qr dog will prompt you to replace all the instances of "cat" with "dog" in the current buffer.

Incremental Searching

During incremental searching, a string is searched for as it is typed. To start a forward incremental search using the command line, use the i_search command (Ctrl+I). To start a reverse incremental search, use the reverse_i_search command (Ctrl+Shift+I). Incremental Search always uses the default search options (see Search Options).

The following key combinations (based on the default CUA emulation) take on a different definition during an incremental search:

Keys

Function

Ctrl+R

Search in reverse for the next occurrence of the search string.

Ctrl+S

Search forward for the next occurrence of the search string.

Ctrl+T

Toggle regular expression pattern matching on/off.

Ctrl+W

Toggle word searching on and off. To change the word characters for a specific language, use the Word chars field on the language-specific General options screen (see Language-Specific General Options).

Ctrl+Shift+W

Copy complete word at cursor to search string.

Ctrl+C

Toggle case sensitivity. The key bound to the Brief emulation command case_toggle will also toggle the case sensitivity.

Ctrl+M

Toggle searching within selection.

Ctrl+O

Toggle incremental search mode.

Ctrl+Q

Quote the next character typed.

Ctrl+S or F5

(Brief emulation) Search forward for the next occurrence of the search string.

Ctrl+R or Alt+F5

(Brief emulation) Search in reverse for the next occurrence of the search string.

Ctrl+W

(GNU Emacs emulation) Copy complete word at cursor to search string.

Ctrl+Shift+W

(GNU Emacs emulation) Toggle word searching on and off.

Incremental searching stops when you press a key that does not insert a character. You can press Esc to terminate an incremental search (only during prompting). Press and hold Ctrl+Alt+Shift to terminate a long search.

You can retrieve your previous search string by invoking the i_search or reverse_i_search command and pressing Ctrl+S or Ctrl+R, respectively, before entering a search string.

Find and Replace Commands

Find and Slash (/) Commands

The command line is available for performing searches. You can use the forward slash (/) or find commands which provide the same functionality as the Find and Replace view. Press Esc to toggle the cursor to the command line.

The syntax of the slash(/) command is:

/string[/OptionCharacters]

The syntax of the find command is:

find /string[/OptionCharacters]

OptionCharacters is one or more of the following option characters:

Option Character(s)

Description

E

Exact case.

I

Ignore case.

-

Reverse search.

M

Limit search to selection.

<

If found, place cursor at beginning of word.

>

If found, place cursor at end of word.

R

Interpret search string as a SlickEdit® Core regular expression.

U

Interpret search string as UNIX regular expression.

B

Interpret string as a Brief regular expression.

N

Do not interpret search string as a regular expression.

P

Wrap to beginning/end when string not found.

W

Limit search to words. Used to search for variables.

W=SlickEdit-regular-expression

Specifies the valid characters in a word. The default value is [A-Za-z0-9_$]. To change the word characters for a specific language, use the Word chars field on the language-specific General options screen (see Language-Specific General Options).

W:P

Limit search to word prefix. For example, a search for "pre" matches "pre" and "prefix" but not "supreme" or "supre".

W:PS

Limit search to strict word prefix. For example, a search for "pre" matches "prefix" but not "pre," "supreme" or "supre".

W:S

Limit search to word suffix. For example, a search for "fix" matches "fix" and "suffix" but not "fixit".

W:SS

Limit search to strict word suffix. For example, a search for "fix" matches "suffix" but not "fix" or "fixit".

H

Allow finding search string in hidden lines.

Y

Binary search. This allows start positions in the middle of a DBCS or UTF-8 character. This option is useful when editing binary files (in SBCS/DBCS mode) which may contain characters which look like DBCS but are not. For example, if you search for the character "a", it will not be found as the second character of a DBCS sequence unless this option is specified.

, (comma)

Delimiter to separate ambiguous options.

X CCLetters

Requires the first character of search string NOT be one of the color coding elements specified. For example, XCS requires that the first character not be in a comment or string. CCLetters is a string of one or more of the following color coding element letters:

  • O - Other

  • K - Keyword

  • N - Number

  • S - String

  • C - Comment

  • P - Preprocessing

  • L - Line number

  • 1 - Symbol 1

  • 2 - Symbol 2

  • 3 - Symbol 3

  • 4 - Symbol 4

  • F - Function color

  • V - No save line

  • A - Attribute

C CCLetters

Requires the first character of search string to be one of the color coding elements specified. See CCLetters above.

*

Used with the "Search hidden text" (H) or "Highlight matches" (#) options to find all matches and un-hide or highlight them.

&

Use Wildcard regular expression syntax (*, ?).

#

Highlight matched patterns with highlight color.

V

(Replace commands only) Preserve case. When specified, each occurrence found is checked for all lowercase, all uppercase, first word capitalized, or mixed case. The replace string is converted to the same case as the occurrence found except when the occurrence found is mixed case (possibly multiple capitalized words). In this case, the replace string is used without modification.

$

(Replace commands only) Replaced occurrences are highlighted with modified color.

If you don't specify options when using the find and (/) commands, the default search options are applied. See Search Options for more information.

If the "*"option is not specified, you will be prompted with the message Yes/No/Last/Go/Quit/Suspend? for each occurrence of the "Search for" string.

Replace and c Commands

The replace commands, replace and c, can be used in the command line. The syntax of these commands is:

c /string1/string2[/options]

or:

replace /string1/string2[/options]

The available options are the same as for the find and slash(/)commands (see Find and Slash (/) Commands above).

You can perform one of the following actions with the replace command (c) by pressing the corresponding key:

Key

Action

Y or Space

Make change and continue searching.

N or Backspace

No change and continue searching.

L or Dot

Make change and stop searching.

G or !

Make change and change the rest without prompting.

Q or Esc

Exit command. By default, the cursor is NOT restored to its original position. If you want the cursor restored to its original position, from the main menu click Window → SlickEdit Preferences → Editing → Search and set the Restore cursor after replace option to True.

Ctrl+G

Exit command and restore cursor to its original position.

Ctrl+R

Search in reverse for next occurrence of search string.

Ctrl+S

Search forward for next occurrence of search string.

Ctrl+T

Toggle regular expression pattern matching on/off. The key bound to the Brief emulation command re_toggle will also toggle regular expression pattern matching.

Ctrl+W

Toggle word searching on/off. To change the word characters for a specific language, use the Word chars field on the language-specific General options screen (see Language-Specific General Options).

Ctrl+C

Toggle case-sensitivity. The key bound to the Brief emulation command case_toggle will also toggle the case-sensitivity.

Ctrl+M

Toggle searching within selection.

F1 or ?

Display Help on Find and Replace view.

Replace Command Search Examples

The table below provides examples of using command line replace.

Example

Description

c $/$\$

Replace occurrences of forward slashes with back slashes.

c/x/y/m

Replace occurrences of "x" in the selected area with "y" using default search case sensitivity.

c $x$y$m

Replace occurrences of "x" in the selected area with "y" using default search case sensitivity. The string delimiter "$" has been used requiring a space character after the "c."

c/x/y/e*

Replace lowercase occurrences of "x" with "y" without prompting.

c/i/something_more_meaningful/w

Replace occurrences of the variable "i" with "something_more_meaningful."

c/i/j/w=[A-Za-z]

Replace occurrences of the word "i" with "j" and specify valid characters in a word to be alphabetic characters.

replace/Test/TEMP/v

Replace occurrences of the word "test" with the word "temp", with the case preserved. For example:

  • Occurrences of "Test" are replaced with "Temp".

  • Occurrences of "test" are replaced with "temp".

  • Occurrences of "tesT" are replaced with "TEMP" (because a mixed case will retain the actual replacement that you typed).

  • Occurrences of "TEST" are replaced with "TEMP".

Find and Replace View

You can use the Find and Replace view (Ctrl+F, Edit → Find/Replace) to specify search and replace options and conduct search and replace operations on selections, single files, or multiple files.

Saving Search and Replace Values

When the Find and Replace view is invoked, the options that were used for your last search are displayed, providing a way to repeat the last search. Options also persist when switching between the tabs. Pressing F7 and F8 retrieves previous and next responses, respectively.

Search and replace values can be saved as named operations. Saving preserves the values of all of the fields in the Find and Replace view so that the search and/or replace operation can be repeated in the future with the same results. To save the search/replace, right-click in the Find and Replace view. Select Saved Search Expressions, then select Save Search Expression from the sub-menu. You will be prompted to name the operation. To access a saved operation, select Saved List from the sub-menu, then pick the saved operation to load.

Syntax-Driven Searching

To reduce the number of false positives in your searches, you can restrict the search based on program syntax. Click the Color button on the Find tab of the Find and Replace view to specify the syntactic elements for filtering. Each check box has three states:

  • Neutral (the default) - All check boxes start in the neutral state. These elements will be used in a search until cleared or until one or more other elements are selected. Putting a check in any check box essentially clears all non-checked boxes.

  • Selected - If the check box is selected, the search will be restricted to this element and any other selected elements. There is no need to clear any other elements if any elements are selected. If any elements are selected, only selected elements will be searched. For example, to search for the word "result" only in comments, put a check only in the Comment check box. All other syntactic elements will be ignored as part of this search.

  • Cleared - If the check box is clear, these elements will not be searched. For example, if you want to find the word "result" anywhere in your code except for in comments, clear the Comment check box.

Setting Options

Options for individual search and replace operations are located on the Find and Replace view. Alternatively, you can set default options that are always used instead. To set the default options, right-click on the background of the view and select Configure Options. The default search options will always be used when the Find and Replace view is invoked, unless settings are changed on the Find and Replace view. If you change settings on the view and want to use the default options instead, right-click in the view and select Use Default Options. See Search Options for more information. For information on the individual options on the Find and Replace view, see Search Dialogs and Views.

Search Results Output

You can specify that multi-file search results are displayed in a new editor window or in a new Search Results view.

To send the results to a new editor window, select the Find in Files tab, click the Result options button to expand the options, then select Output to editor window.

To send the results of a multi-file search to a specific Search Results view, select the Find in Files tab, click the Results optionsbutton to expand the options, then use the Search Results Window drop-down list to select the window to be used. These are labeled starting at Search<0>. A new results view can be added with the <New> option up to a pre-set limit of open Search Results windows.

If <Auto Increment> is selected from the Search Results Window drop-down list, the search results will cycle through all of the open Search Results tabs in the Search Results view with each new search. For example, if you have Search<0>, Search<1>, and Search<2> open, then for each search operation, the results will be displayed in this order: Search<0>, Search<1>, Search<2>, Search<0>, Search<1>, and so on. If you only have one Search Results view open, then all results will go into the only open search windows. You can open and close search results windows by right-clicking on the Search Results tab in the Search Results view.

Right-click in the Search Results window to access the following options:

  • Quick Search - Finds the next occurrence of the text selected.

  • Filter Search Results - Select this option to display the Filter Search Results dialog. From here, if a match is found, you can choose to keep or delete lines with additional searches, match case, limit to current default regular expression syntax and/or remove matches found on the same line number in the same file (this can also be accomplished by selecting List matching lines only from the Find in Files tab).

  • Open as Editor window - Opens current search results in a new editor window.

  • Go to Line - Goes to the file/line number of the current line in the Search Results window.

  • Bookmark Line - Places a bookmark at the line in the file where the result was found.

  • Clear Window - Clears all results in the current Search Results window.

  • Align Columns - Aligns the line numbers and column numbers for all search results.

  • Collapse All - Collapses all Selective Display levels. See Selective Display for more information.

  • Expand All - Expands all Selective Display levels. See Selective Display for more information.

See Find in Files Tab for more information.

Find Symbol View

The Find Symbol view (Search → Find Symbol or gui_push_tag command) is used to locate symbols in your code. It allows you to search for symbols by name using either a regular expression, substring, or fast prefix match.

Searching for a symbol is faster than a normal text search because it is executed against the Context Tagging® database, rather than searching through your source files. Find Symbol also avoids false hits in comments or string literals. Though Syntax-Driven Searching in the regular Search Dialogs and Views provides this same capability, it cannot match the speed of Find Symbol.

See Find Symbol View for information about the options that are available.

Find and Replace with Regular Expressions

SlickEdit® Core supports five types of regular expression syntax that you can use for finding and replacing when regular search and replace operations are too limiting:

  • Brief

  • Perl

  • SlickEdit

  • UNIX

  • Wildcards

See Regular Expressions for more information.

Undoing/Redoing Replacements

To undo a replacement, click Edit → Undo, press Ctrl+Z, or use the undo command. To redo a replacement, click Edit → Redo, press Ctrl+Y, or use the redo command.

To undo replacements in multiple files, click Edit → Multi-File Undo or use the mfundo command. To redo replacements in multiple files, click Edit → Multi-File Redo or use the mfredo command.

Match Highlighting

Cursor on Symbol Shows All Uses in File

SlickEdit® Core can highlight all occurrences of the current symbol under the cursor. This makes it easy to see, at a glance, all uses of a symbol in a file. This option can be set on a language-specific basis. To enable it, from the main menu, click Window → SlickEdit Preferences → Languages, expand your language category and language, then select Context Tagging®. On the options screen, select Highlight matching symbols under cursor.

The highlight color is controlled by the Symbol Highlight screen element (Window → SlickEdit Preferences → Appearance → Colors). To change the color, see Setting Colors for Screen Elements. See Language-Specific Context Tagging® Options for information about other options on the options screen.

This feature includes two advanced options that affect all languages that have Highlight matching symbols enabled. These can be set through configuration variables (Macro → Set Macro Variable):

  • def_highlight_symbols_max_bufsize - This variable sets the maximum buffer size, in bytes, for symbol highlighting. If the buffer size is greater than the max size, highlighting is restricted to the visible lines.

  • def_highlight_symbols_max_matches - This variable sets the maximum number of matching occurrences for symbol highlighting.

See Setting/Changing Configuration Variables for more information.