Flag of the United Kingdom
Andreas Rejbrands webbplats

Rejbrand Text Editor 3.1: Text transformation

Last time, we had a look at some of Rejbrand Text Editor’s features related to Unicode characters. This time, we will focus on some of the text transformation features of the software.

Of course, all text editors have features for “transforming” (or “editing”) text files and almost all Windows editors offer standard keyboard (and mouse) navigation and input (character keys, Backspace, Delete, arrow keys, Home, End, Ctrl+something, selections, ...) and the standard interface to the operating system clipboard, and we will not say anything about these bare-minimum features. Instead, we will concentrate on the text-transformation features that are not found in every editor, and certainly not in simple editors like Notepad. We proceed by giving examples of actual text-transformation scenarios and their possible solutions using Rejbrand Text Editor.

Paste as

Suppose you have a few paragraphs of text in Microsoft Word and you need to obtain their HTML representation. This amounts to surrounding each paragraph by <p> and </p>. Rejbrand Text Editor can do this for you, using the Edit/Paste as feature:

A screenshot of the Paste Special dialog box in Rejbrand Text Editor, about to paste a few paragraphs of text as HTML paragraphs.

In one of my regular workflows, I also need the hypertext code to be single line. Hence, I replace all line breaks with the empty string in the pasted text:

A screenshot of the Replace dialog box in Rejbrand Text Editor, about to remove all line breaks in the file.

(This might cause a very long line to appear. To navigate this, I personally appreciate the scrolling mode entered by holding down the Alt key. In this mode, I can pan the document by dragging it using the mouse. More generally, in this mode all actions that normally would move the caret now scrolls the document, such as the arrow keys and dragging the mouse. Instead of holding down the Alt key, you can enter this mode by toggling the Scroll Lock key to the “on” state.)

Multiple carets

Suppose you have the following HTML snippet and need to add the directory Docs to all hyperlinks:

<ul>
<li><a href="limits.html">Limits</a></li>
<li><a href="antiderivatives.html">Antiderivatives</a></li>
<li><a href="derivatives.html">Derivatives</a></li>
<li><a href="integrals.html">Integrals</a></li>
<li><a href="odes.html">Differential equations</a></li>
</ul>

Of course, you could select the block and replace all instances of href=" with href="docs/, but it is easier with multiple caret input. Simply put the caret after href=" on the last line and press Ctrl+Up four times (or, put the caret on the first line and press Ctrl+Down four times). Then type docs/ and press Esc to exit multiple caret mode:

Text being inserted in multiple-caret mode in Rejbrand Text Editor.

In multi-caret mode, which you can also enter by pressing Ctrl+M, you may add new carets anywhere by clicking using the mouse. Hence, the carets need not be above/below each other. You may even have multiple carets on a single line:

Text being inserted in multiple-caret mode in Rejbrand Text Editor.

Also notice that the second and the third list items (“Antiderivatives” and “Derivatives”, respectively) should be swapped, because you must learn about derivatives before you can learn about antiderivatives. To do so, put the caret on the second line and press Shift+Ctrl+Down or on the third line and press Shift+Ctrl+Up.

Overwrite mode

Although overwrite mode is a feature found in most text editors (but not Notepad as of Windows 7), it is probably not as well known as it should be. Because of this, I want to give an example of when it can be useful. Suppose you want to enter this source code:

arr[1] := 10;
arr[2] := 20;
arr[3] := 30;
arr[4] := 40;
arr[5] := 50;
arr[6] := 60;
arr[7] := 70;
arr[8] := 80;
arr[9] := 90;

The easiest way to do this is likely to write the first line, copy it eight times, and then update the numbers using overwrite mode, which you enter by pressing the Insert key:

Text being inserted in overwrite mode in Rejbrand Text Editor.

Filter lines and Truncate lines

Consider the following HTML table:

<table>
<caption>Greek letters</caption>
<tr>
<th>Code</th>
<th>Character</th>
<th>Description</th>
</tr>
<tr>
<td>\Alpha</td>
<td>Α</td>
<td>U+0391: GREEK CAPITAL LETTER ALPHA</td>
</tr>
<tr>
<td>\alpha</td>
<td>α</td>
<td>U+03B1: GREEK SMALL LETTER ALPHA</td>
</tr>
<tr>
<td>\Beta</td>
<td>Β</td>
<td>U+0392: GREEK CAPITAL LETTER BETA</td>
</tr>
<tr>
<td>\beta</td>
<td>β</td>
<td>U+03B2: GREEK SMALL LETTER BETA</td>
</tr>
<tr>
<td>\Gamma</td>
<td>Γ</td>
<td>U+0393: GREEK CAPITAL LETTER GAMMA</td>
</tr>
<tr>
<td>\gamma</td>
<td>γ</td>
<td>U+03B3: GREEK SMALL LETTER GAMMA</td>
</tr>
...

Given this table, we would like to extract the following list:

U+0391: GREEK CAPITAL LETTER ALPHA
U+03B1: GREEK SMALL LETTER ALPHA
U+0392: GREEK CAPITAL LETTER BETA
U+03B2: GREEK SMALL LETTER BETA
U+0393: GREEK CAPITAL LETTER GAMMA
U+03B3: GREEK SMALL LETTER GAMMA
...

This is very easy using the Edit/Filter lines feature. Simply keep only lines containing the text “U+”:

A screenshot of the Filter Lines dialog box in Rejbrand Text Editor.

This yields

    <td>U+0391: GREEK CAPITAL LETTER ALPHA</td>
<td>U+03B1: GREEK SMALL LETTER ALPHA</td>
<td>U+0392: GREEK CAPITAL LETTER BETA</td>
<td>U+03B2: GREEK SMALL LETTER BETA</td>
<td>U+0393: GREEK CAPITAL LETTER GAMMA</td>
<td>U+03B3: GREEK SMALL LETTER GAMMA</td>
...

Now, search for <td> and replace with the empty string (Ctrl+R), and do the same for </td>. Finally, remove all leading whitespace (indentation) by selecting the block (if that is the entire file, by pressing Ctrl+A) and pressing Shift+Ctrl+Backspace. (Or, use Edit/Remove all indent.)

Now you see this:

U+0391: GREEK CAPITAL LETTER ALPHA
U+03B1: GREEK SMALL LETTER ALPHA
U+0392: GREEK CAPITAL LETTER BETA
U+03B2: GREEK SMALL LETTER BETA
U+0393: GREEK CAPITAL LETTER GAMMA
U+03B3: GREEK SMALL LETTER GAMMA
...

You suddenly realise that you only want the capital letters. Easy! Just filter the lines again, using “CAPITAL” as the text to filter for:

U+0391: GREEK CAPITAL LETTER ALPHA
U+0392: GREEK CAPITAL LETTER BETA
U+0393: GREEK CAPITAL LETTER GAMMA
...

If you only want the descriptions, not the codepoints, you can use the Edit/Truncate lines feature (screenshot). In this case, you may truncate at the first occurrence of the colon (“:”) from the beginning of the line, removing the colon itself. Make sure to perform a reverse truncation, so that the text after the colon is preserved, not the text before it. Then remove the leading whitespace as before:

GREEK CAPITAL LETTER ALPHA
GREEK CAPITAL LETTER BETA
GREEK CAPITAL LETTER GAMMA
...

(In this very simple case, it would have been easier to truncate at the fixed column 9 or at the first occurrence of the space character. Then we wouldn’t have needed to remove the leading space characters. In a small list, we could also have used multiple carets and Backspace or a block selection (to select the “U+NNNN: ” block) and Delete or Backspace.)

Block paste etc.

Suppose you have this source code and need the same code but with all assignments reversed:

eFirstName.Text := FFirstName;
eLastName.Text := FLastName;
eTitle.Text := FTitle;
eCompany.Text := FCompany;
eHomeStreet.Text := FHomeStreet;
eHomePostalCode.Text := FHomePostalCode;
eHomeCountry.Text := FHomeCountry;
eHomePhone.Text := FHomePhone;
eWorkStreet.Text := FWorkStreet;
eWorkPostalCode.Text := FWorkPostalCode;
eWorkCountry.Text := FWorkCountry;
eWorkPhone.Text := FWorkPhone;
eCellphone.Text := FCellphone;
eHomeEmail.Text := FHomeEmail;
eWorkEmail.Text := FWorkEmail;
eWebsite.Text := FWebsite;

Here is one way:

Fill with character

A source code file might begin with the following multi-line comment:

{******************************************************************************}
{ }
{ Rejbrand Text Editor Control 3.1 }
{ }
{ Copyright © 2015-2018 Andreas Rejbrand }
{ }
{ https://english.rejbrand.se/ }
{ }
{******************************************************************************}

Suppose you want to use this comment as a template for a new comment, similar but different, in a new source code file. Then you’d like to replace all text with new text. This is actually easy: Simply make a block selection (Ctrl-dragging the mouse or using Shift+Alt+Arrow keys etc.) of the interior of the comment, select Edit/Fill with character, and fill it with space:

Filling a block selection with space characters in Rejbrand Text Editor.


Visa alla tidigare notiser.

Visa enbart de senaste notiserna.