How may I insert a lone dot on a line with the ed
editor? Normally, a dot on a line by itself ends the insertion; can it somehow be escaped?

- 333,661

- 229
1 Answers
No, you cannot insert a period on a line by itself, because that's ed
's instruction to stop inserting text; see one of the early ed man pages (page 7):
Input mode is left by typing a period (.) alone at the beginning of a line.
You can work around it by not entering a period by itself; for example: Space.Enter followed by .Enter followed by s/^ //
. You could use any other character than Space as the token, as long as you pair it in the subsequent s//
command.
A period cannot be inserted by itself; when appending, changing, or inserting a line, ed
ends up calling the append_lines
function; that function, in buffer.c, reads input delimited by a newline (via get_stdin_line
). As part of that, it checks to see if a period is the only thing (besides the trailing newline) in the result; below, "ibufpp" is the pointer to the inputted text and "size" is the length of that buffer:
if( size == 2 && **ibufpp == '.' ) { *ibufpp += size; return true; }
You can download compressed tar bundles at: http://download.savannah.gnu.org/releases/ed/ or view Debian's upstream page for ed or OpenBSD's page for ed where the corresponding code is in main.c.
Another option, discovered in an ed(1) Conference twitter post, is to enter any other single character, then replace that character with a period:
- xEnter
- .Enter
s/./.

- 333,661

- 67,283
- 35
- 116
- 255
/
, then use an unanchoreds/k//
(withk
as an example), if you find that faster to type. – Jeff Schaller Nov 08 '19 at 20:21ed
by default), the relevant code is line 1046 inmain.c
: https://github.com/openbsd/src/blob/master/bin/ed/main.c#L1046 Other BSDs are likely using this variant ofed
too. – Kusalananda Nov 09 '19 at 12:18..
on the protocol level (and any other lines that start with a dot get that dot removed). – ilkkachu Nov 09 '19 at 12:33ed
. I was honestly not aware that this was called "input mode", and I was obviously wrong in saying there was no such thing.ed
(a line editor) being very different fromvi
(a screen editor), the modes "feel" very different though. The current phasing in the question does not feel odd or wrong at all, but feel free to change back if you wish. – Kusalananda Nov 09 '19 at 22:30