1

In GNU ed, is there a way to cancel the current input? For example:

$ ed myfile.txt
1234
a
Wrong speling.
Bad sentance.

At this point, I want to cancel the input. I no longer want to insert the two lines that I have typed. Is it possible? I thought of continuing like this:

.
u

Is using "undo" the usual method for cancelling an input? Are there other ways?

Flux
  • 2,938

1 Answers1

0

You can't "cancel" input, as in "starting to append several lines of text but then not actually appending them".

While adding text with e.g. the a command, a single line of text may be cancelled by pressing Ctrl+D twice before pressing Enter. Doing so also terminates the current editing command. You can't cancel the addition of more than the current line in this way. Depending on your system and ed variant, pressing Ctrl+D twice in insertion mode may or may not give you a new line to type the next command on (does on OpenBSD, does not on Ubuntu Linux).

The above "trick" (undocumented feature) does not work if you use ed together with rlwrap to get command history and Readline editing capabilities.

You can undo the whole operation once you have finished it, just like how you show. You end the insertion of text with . on a line of its own and then issue the u (undo) command. You could also end the text insertion with Ctrl+D on a new line and then use the u command.

The ed editor has a single level of undoing, which means you may undo the most recent command only. Undoing twice undoes the undo. If you apply multiple commands to the text with a single g, v, G, or V command, then this counts as one single command that you may undo if you need to do so.

Kusalananda
  • 333,661