How to escape period in ed

803 Views Asked by At

I'm studying the ed text editor.

To exit from input mode, a user should enter a line a single period (.).

Let's say I want to enter the period as text.

I thought of a workaround: first, I insert something like ... Then, I replace .. with ..

But my approach is little unwieldy. Is there a better way to do this?

2

There are 2 best solutions below

1
On

Reading through the C source for GNU ed(1), there is no escape character. On the occasions that I've wanted to do this, I tend to add a blank line and then use a quick substitution:

a↵
↵
.↵
s/^/.↵

or you can add a character then delete it (which, if you're playing ed(1) golf), is one character more than above)

a↵
x↵
.↵
s/./.↵
0
On

I didn't found magic escape sequence.

It seems it doesn't exist.

But this link offers 2 solutions. First I described in my question. Second one is closer to a solution with escape.

r ! echo .