Finding

The editor has two ways to search. The Find / Replace panel searches the procedure, the file or the whole project, and replaces text. The Quick Find widget searches the file you are in, in a small box over the code.

The Find / Replace panel

Open the panel with one of these:

To Do this
Find Edit → Find…, Ctrl+F
Find and replace Edit → Replace…, Ctrl+H
Search the whole project Edit → Find In Project…, Ctrl+Shift+F, or the Find In Project… button of the toolbar
Show the panel without searching View → FIND / REPLACE

Ctrl+F and Ctrl+H do the same thing: both open the panel, and the panel has no separate mode for replacing. They fill Find What with the word at the caret, or with the selection, clear Replace With, and put the focus in Find What with its text selected. A selection of several lines fills Find What with the first line, and ticks Selected Text.

The panel is in no built-in layout. The first time you show it, it floats. You can dock it like any other panel; see Panel layouts.

The Find / Replace pane. Find What and Replace With are both empty. The scope radio group has Current File selected, with Current Procedure, Current Module and Selected Text greyed out. Direction is set to All, and the checkboxes Whole Word Only, Match Case, Pattern Matching and Match Regular Expressions are all clear, while Inside Packages is greyed out. Find Next, Cancel, Replace and Replace All run down the right edge.The Find / Replace pane. Find What and Replace With are both empty. The scope radio group has Current File selected, with Current Procedure, Current Module and Selected Text greyed out. Direction is set to All, and the checkboxes Whole Word Only, Match Case, Pattern Matching and Match Regular Expressions are all clear, while Inside Packages is greyed out. Find Next, Cancel, Replace and Replace All run down the right edge.

The labels of the panel are in English whatever the IDE language is.

The controls

Find What
The text to find. Enter runs Find Next. Click the label to select the text in the box.
Replace With
The text that replaces a match. Enter runs Find Next.
Current Procedure
Searches the procedure the caret is in. It is available only while the caret is inside a procedure.
Current Module
This scope is always greyed out. Use Current File.
Current File
Searches the file you are editing. It is the scope the panel takes when you move the caret into a file and no scope is ticked.
Current Project
Searches every file of the project. See Search the whole project.
Selected Text
Searches only the selection. It is available only while some text is selected.
Direction
All, Down or Up. With All, a search that reaches the end of its scope goes round to the other end without asking.
Whole Word Only
A match counts only when the characters before and after it are not letters or digits. An accented letter next to the match, such as é, also stops it counting.
Match Case
Tells capital and small letters apart. Without it, a plain search ignores case. Ticking it clears Match Regular Expressions.
Pattern Matching
Reads Find What as a pattern, like the Like operator. Ticking it clears Match Regular Expressions.
Match Regular Expressions
Reads Find What as a regular expression. Ticking it clears Match Case and Pattern Matching.
Inside Packages
Includes the packages the project references in a project search. It is available only with Current Project.
Find Next
Finds the next match in the direction, and selects it in the editor.
Replace
Replaces the selected match and finds the next one. The first press only finds a match; later presses replace.
Replace All
Replaces every match in the scope. A project search refuses it; see Search the whole project.
Cancel
Closes the panel. It shows only while the panel floats.
The Direction dropdown with its list open below it, offering All, marked as the current choice, then Down and Up.The Direction dropdown with its list open below it, offering All, marked as the current choice, then Down and Up.

The panel keeps the text of Find What and Replace With that you searched with, and the options. Down in the Find What box shows the newest search, and each further Down an older one. Up goes back to newer ones. The IDE keeps this history and the options for each project.

Keys

Key What it does
F3 Find Next, from the editor or the panel.
Shift+F3 Find Previous.
Esc Closes the panel when it floats, and puts the focus in the code.

These keys work only while the focus is in the panel:

Key What it does
Alt+N Find Next.
Alt+R Replace.
Alt+A Replace All.
Alt+F, Alt+W Go to Find What, go to Replace With.
Alt+P, Alt+C Choose Current Procedure, Current Project.
Alt+D Go to Direction.
Alt+O, Alt+S, Alt+U Tick Whole Word Only, Match Case, Pattern Matching.

Match Regular Expressions and Inside Packages have no key.

What a search says

A search that reaches the end of its scope with Down asks End of search scope has been reached; do you want to continue from the beginning? With Up it asks Beginning of search scope has been reached; do you want to continue from the end? The buttons are Yes and No.

A search with All, a project search, and Replace All end with The specified region has been searched. After a Replace All, a second box says how many replacements were made: N replacements were made., or 1 replacement was made. With no scope ticked, the panel says Scope not selected.

Note

In twinBASIC BETA 1005, after a search of Selected Text, moving the caret leaves Selected Text ticked but greyed out, and Current File is no longer ticked. Find Next then says at once that the end of the search scope has been reached. Tick Current File again to search on.

Match text

A plain search ignores case unless Match Case is ticked.

Pattern matching

With Pattern Matching, Find What is a pattern like the one the Like operator reads:

Pattern Matches
? Any one character.
* Any run of characters, including none.
# Any one digit.
[abc] Any one of the characters in the brackets.
[!abc] Any one character not in the brackets.

For example, Tw?ce finds Twice, [AV]rea finds Area, and Area(#, #) finds a call with two single-digit numbers. * takes as much as it can, so W*Optional finds from the first W to the last Optional on the line.

Regular expressions

With Match Regular Expressions, Find What is a JavaScript regular expression, written between slashes with optional flags after the second slash: /pattern/flags. The flags can be g, i, m, s, u and y. The panel adds m itself. For example, /to+tal/i finds total in any case.

If Find What is not in the /pattern/flags form, a box says Invalid format. Expecting /pattern/flags. If the pattern is not a valid expression, a box says Invalid RegExp:.

Note

In twinBASIC BETA 1005, a regular expression whose match spans a line break, such as /^\s+end sub$/, selects nothing. The selection is an empty one at the end of the line before the match, and Find Next stays there. Search for one line at a time.

Note

In twinBASIC BETA 1005, the Invalid RegExp: box leaves out the reason. It shows the words and nothing after them.

Search the whole project

Find In Project has no dialog and no list of results of its own. It opens the Find / Replace panel with Current Project ticked, and you go through the matches with Find Next.

The Find / Replace panel floating over the editor, with Twice in Find What, Current Project ticked, and Inside Packages available but not ticked. Behind it, Find Next has gone on to a second file and selected the match Twice in its line Count = Count + Twice(n).The Find / Replace panel floating over the editor, with Twice in Find What, Current Project ticked, and Inside Packages available but not ticked. Behind it, Find Next has gone on to a second file and selected the match Twice in its line Count = Count + Twice(n).

A project search:

  • starts in the file you are editing, goes on through the files after it in the order of the Project Explorer tree, and then through the files before it, ending back in the first part of the start file;
  • looks in .twin, .bas, .cls and .md files, and skips every file whose name starts with a dot;
  • does not look in the packages unless Inside Packages is ticked;
  • does not look in forms (.tbform files);
  • always goes down, whatever Direction says;
  • opens each file that holds a match in a tab. The tab is a preview tab when File Explorer: Single-Click Preview is on.

Replace All does not work in a project search. The panel says Sorry, Replace-All not yet supported in project-scope. Use Replace and Find Next to go through the matches one at a time, or switch to Current File and repeat the replacement in each file.

Quick Find

The Quick Find widget searches the file you are in, with a small box at the top right of the editor.

To Do this
Open Quick Find Edit → Quick Find…, Alt+F
Open it with the replace row Edit → Quick Replace…, Alt+H
Close it Esc, which returns the focus to the code
Go to the next match Enter, or Alt+F3
Go to the previous match Shift+Alt+F3
Show an earlier search Up
Show a later search Down

The widget opens with the selected text in its box, and with the count of the matches, such as 1 of 10. Its toggles are Match Case, Match Whole Word, Use Regular Expression and Find in Selection, and the replace row has Preserve Case. Shift+Enter does nothing. The IDE does not remember the toggles between uses.

The Quick Find widget at the top right of the editor, opened with Quick Replace so that its replace row shows. Its box holds Twice, with the toggles beside it and the count 2 of 2, and both matches of Twice are marked in the code.The Quick Find widget at the top right of the editor, opened with Quick Replace so that its replace row shows. Its box holds Twice, with the toggles beside it and the count 2 of 2, and both matches of Twice are marked in the code.

With a word selected, Ctrl+F3 in the code goes to its next occurrence and shows the widget.

Select all matches

Edit → Select All Matches (Alt+A) opens the widget, gives a cursor to every match of the text in it, and closes the widget. You can then type to change every match at once; see several cursors. Ctrl+Shift+L does the same with the word at the caret, with no widget.

While the focus is in the Find / Replace panel, Alt+A is Replace All and Alt+F goes to Find What. In the editor they run Select All Matches and Quick Find.

See Also

  • Edit menu – the menu that holds the find commands
  • Editor – Change All Occurrences and the other editing commands
  • Navigating – move by definition, bookmark or line