ed is a simple text editor, which can be used where usage of a terminal is not supported, or visual editors (such as vi) are not available. Note that most of content of this page has taken from ed(1) man page, with help of @artsi0m on telegram. but this document won't explain ed commands and features completely, please read that.

ed has two modes, first one is command mode, which is default mode when you open ed, second one is input mode, which is used for adding text into your file like any other editor.

input mode

as mentioned before, input mode is where you change the text directly using stdin of your terminal. below, are few examples of commands can used to start input mode:

aappend text the end of file
iinsert text to current line
cchange and replace current line

note that you can exit input mode and switching back to command mode using a single dot (.) on a blank line and length of file will shown afterwards. for example:

$ ed file
Hello, world.

basic examples

opening a file:

$ ed file

using a custom prompt:

$ ed -p  '~' file

using ed without noise, suitable for usage on scripts:

$ ed -s file

basic ed commands

note that you can combine some (if not all?) commands, like wq for writing and quitting.

aappend, for adding text into the end of your file (or buffer).
eopens first argument as file to edit (!command is accepted). cleans buffer before doing this. if there is no argument, uses default file name (see f).
Elike e, but won't show warnings about unwritten changes
fsets default filename (see f)
Hprints error explanation for next errors
hprints error explanation for the last error
nsame as p, but shows with line numbers.
pmeans print, to show the file you are editing.
Ptoggles prompt, enabled only when you've used -p while executing ed
Qlike q, but won't show you a warning about unsaved stuff
qquits ed
uundo, only saves last thing (this includes undo too, of course)
rread from file (or !command), can take a address. (like 9r will open 9th line)
wwrites buffer into file
=works like wc -l
any numberswitches to that line, for example 9 will switch to 9th line of file ( or buffer?)

advanced ed commands

m,nddeletes mth line until nth line in buffer
m,nG/re/finds and moves on lines which include regular expression re from mth line, until nth line
m,njjoins all lines from mth line to nth line
m.ng/re/commandfinds all lines containing re regular expression and executes (ed) command on them.
s/re/replacementsreplaces all all "re"'s with replacements
m.nV/re/like G, but reverse (all lines that does not contain re)

ed symbols

, or %all lines from first line until current line
??repeats last search done by ?re?
?re?previous line containing regular expression re
-n or ^nnth previous line
- or ^previous line
nnthn line in buffer
.current line
$last line in buffer
+nn line upper
/re/next line containing regular expression re
//repeats last search done by /re/
+one line upper
%file name
'lcshows (book?)marked line in buffer (see k command)