How to escape period in ed
Asked Answered
P

2

6

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?

Peeler answered 26/10, 2013 at 15:10 Comment(1)
Your approach is fine, it's even suggested by POSIX: The typical method of entering a single <period> has been to precede it with another character and then use the substitute command to delete that character. And POSIX also specifies that there are no escape characters in input mode.Mainly
P
6

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 .
Peeler answered 26/10, 2013 at 15:19 Comment(0)
A
6

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/./.↵
Ambler answered 23/5, 2015 at 18:25 Comment(1)
For the record, this is also what diff -e does. diff -e <(echo) <(printf '.\n')Ambler

© 2022 - 2024 — McMap. All rights reserved.