Replace Line Enders

Contents  Previous  Next

 

Menu: Search > Replace Line Enders

 

Default Shortcut Key: Ctrl+Alt+R

 

Macro function: ReplaceLineEnders()

 

The Replace Line Enders command can be used to search for a text string and replace it with another string.  Replacements can be made selectively or globally, within the current file or across all edited files.  Regular Expressions can be entered within the search string.

 

Unlike the Replace command, the Replace Line Enders command can be used to perform search and replace operations that span lines, and which may result in the addition or removal of lines from the file.

 

bm2 Important Note: The Replace Line Enders command performs its replacements unconditionally, without user confirmation.  When large operations are performed, Undo may be unavailable.  For these reasons, it's advisable to make a backup copy of your file before using this command.

 

The controls and options in the Replace Line Enders dialog box are described below:

 

SearchReplaceLineEnders

 

Find text

This is the edit box where the search string is entered.  When the Replace Line Enders command is issued, the word beneath the text cursor is placed into the Find Text edit box, in case that word--or a word which is nearly the same--is to be the search string.  To recall a search string which was previously entered, use the drop-down list or press the up or down arrow keys to review the items in the history list.  Regular Expressions may be used within the search string.

 

Use the sequence \n to represent a line ender (newline).  Example: if you are searching for a line that ends with 'jelly' that occurs just before a line that starts with 'bean', your search string would be: jelly\nbean

 

 

bm1The Delete key can be used while the drop-down list is displayed to delete a selected entry from the history list.

 

bm1Special characters can be entered into the Find text edit box using the technique described in the Help topic Inserting Special Characters.

 

Replace with

This is the edit box where the replace string is entered.  To recall a replace string which was previously entered, use the drop-down list or press the up or down arrow keys to review the items in the history list.

 

Use the sequence \n to represent a line ender (newline).  Example: if you wanted to add two blank lines after all lines that end with the text THE FOLLOWING:, theses search and replace strings would be used:

 

Find text: THE FOLLOWING:\n

Replace with: THE FOLLOWING:\n\n\n

 

 

bm1The Delete key can be used while the drop-down list is displayed to delete a selected entry from the history list.

 

Insert Tab

Use this button to insert a tab character into the Find text or Replace with edit boxes.

 

Ordinarily, the Tab key is used to move from field to field within a dialog box.  If you would prefer that the Tab key insert a tab character in this dialog box, and in other Find/Replace related dialog boxes, check the relevant box on the Configure | Preferences | Tabs dialog page.

 

Scope

Selected text

This option can be used to restrict the search and replace operation to the extent of the selected text.

 

Cursor to bottom

This option causes the search and replace operation to be performed from the cursor onward, toward the end of file.  (There is no provision for making replacements in a backward direction.)

 

Top to bottom

This option causes the search and replace operation to be performed from the top of file onward, toward the end of file.  (There is no provision for making replacements in a backward direction.)

 

All open files

This option causes the search and replace operation to be performed across all open files.

 

Active project

Use this option to limit the scope of the Find operation to those files within the active project.

 

Search Options

Perl regular expressions

If this box is checked, wildcard characters within the search string will be interpreted according to the Perl-Compatible Regular Expression (PCRE) convention.  In part, this means that the asterisk (*) will cause a match of zero or more occurrences of the preceding character.  The period (.) will match any single character. For more information, see Regular Expressions.

 

Maximal matching

When using pattern matching characters, there can sometimes be more than one text string that matches the search string. This option can be used to request that the longest possible matching string be returned.

 

Match case

This option can be used to force the search string to be matched exactly. When unchecked, a case insensitive search is performed.

 

Match whole words

This option can be used to restrict matches to those strings which appear as a whole word.  The characters which serve to delimit words are user-configurable; see Configure | Preferences | Cursor Travel.

 

Match at start of line

This option can be used to force the search string to be matched only when a matching string appears at the start of a line.  This effect can also be achieved with a Regular Expression.

 

Match at end of line

This option can be used to force the search string to be matched only when a matching string appears at the end of a line.  This effect can also be achieved with a Regular Expression.

 

Replace Options

Process $1, $2, $3... substring directives in the replace string

When this option is checked, special directives in the replace string will be replaced at match-time with subpatterns from the search string. This is a very powerful feature, as the following examples will illustrate.

 

Example 1:

 

       Find text: (\w+),(\w+)

       Replace with: $2 $1

 

The search string will match a string of one or more word characters followed by a comma, followed by another string of one or more word characters.  For example: Smith,John.  The parentheses are used to define subpatterns.  The first open parenthesis indicates subpattern number 1, the next number 2, and so on.  In this way, the replace string can vary depending on what the search string matches.  If the string Smith,John is matched, then the replace string will be John Smith.  Running this search and replace operation on a data file would have the effect of inverting a list of Lastname,Firstname data to Firstname Lastname.

 

Example 2:

 

       Find text: (Boxer|BOXER)

       Replace with: <b>$1</b>

 

The search string will match either Boxer or BOXER.  The replace string will be equal to whatever the string matched, surrounded by the HTML open-bold and close-bold sequences.  In this way, the target word can be replaced without regard to its case, while ensuring that no case conversion occurs due to the replacement.

 

bm2The entire matching string is designated as $0, even if subpatterns are not used.  Up to 100 subpatterns can be referenced, numbering from $0 to $99.

 

Sort history lists

If this box is checked the search and replace history lists will be maintained in alphabetic order, rather than in the order the strings were entered.

 

bm2When switching to alphabetically sorted lists, the chronological ordering of the lists will be lost, and cannot be restored by unchecking the checkbox.

 

bm2No attempt is made to associate the history list entries with the time that they were added to the list.  If a sorted history list is used consistently, over time the list will come to hold an unrepresentative set of search phrases.  In the extreme case, after many Replace operations, a list could result that contained only phrases beginning with the letter 'A'.  This occurs because entries at the bottom of the list will be removed after the maximum size of the list is reached.