0

In ed there is the useful c command which allows one to make changes to a specific line. (Using rlwrap as well allows for easier changes, once a line has already been changed, because one can use the up and down arrows to introduce a previous change.)

One feature that would make such changes a lot easier would be for ed to copy the line to be changed without the need to retype all or most of it again, and one could simply use the back arrow to make whatever changes are required, without having to use the mouse to copy and paste the line to edited.

For example:

1 This line must be changed
c
This line must be changed

Rather than this, which is the default behavior:

1 This line must be changed
c
BLANK LINE

I am not sure if this is at all possible using a program outside of ed?

Edman
  • 492
  • Showing the text to be edited and allowing interaction with it is rather more a thing for some sort of VIsual editor. – thrig Jul 06 '22 at 11:51
  • I used ed for all my editing tasks, and would like to avoid going in the direction of something else, but I do understand what you mean. – Edman Jul 06 '22 at 15:24
  • 1
    Using rlwrap would allow you to do editing history recall, but it's not exactly what you have asked for. You would type c followed by Ctrl+R and whatever you're searching for, or Esc-/ if your readline is in Vi mode. – Kusalananda Jul 12 '22 at 18:03
  • That is pretty close to what I was looking for. Multis gratiis. – Edman Jul 13 '22 at 13:52

1 Answers1

1

When you change a line with the c command in ed, the editor asks you what to replace the line with. It does not pre-fill the replacement with the old contents of the line because, being a simple line editor, it would not have any way of allowing you to modify the new text interactively.

However, if you use ed with the Readline library wrapper rlwrap, this will give you the added ability to do inter-line editing in Readline before submitting the text to ed. In particular, if you have written the line that you want to change recently enough (so that it's still in Readline's history), you may be able to use Up-Arrow or whatever other appropriate keybinding to cycle or search through the history for the line and edit it after issuing the c command.

The size of the history saved via rlwrap is adjustable with the -s option to that utility or via editing your Readline configuration file, ~/.inputrc. This is the topic of another question: How to increase the size of the .ed_history file


Annotated ed editing session (the # and the stuff after are added annotations to the session) that creates a document with two lines and changes the first in the way discussed above:

$ rlwrap ed newfile                     # start ed with rlwrap
newfile: No such file or directory
a                                       # add lines
this line must change
this line is ok
.                                       # done adding lines
1c                                      # change first line
this line is now ok too                 # pressed up-arrow to find the old line, edited it
.                                       # done changing
,n                                      # output all lines with line numbers
1       this line is now ok too
2       this line is ok
Kusalananda
  • 333,661