Start ed with -p string
to use string as a visible command prompt.
ed -p ":" ed.html
Basic command syntax:
[addr [,addr]]command[params]
where addr specifies a line or range of lines to operate on.
Line numbers start at 1;
an address of 0 is legal where sensible.
Special address characters:
.
: The current address.$
: The last line in the buffer.-
or ^
: the previous line.
May be repeated for second-previous line, and so on.-n
or ^n
: the nth
previous line, where n is a nonnegative integer.+
: The next line. May be repeated.+n
: The nth next line.,
or %
: 1,$
; all lines.;
: Current to last line; .,$
/re/
: The next line matching regex
re
.?re?
: Same as /re/
,
but backwards.'c
: The line marked by a k
command, where c is a lowercase letter.Commands, with default address in the parentheses:
(.)a
: Insert (append) text
after the addressed line.(.,.)c
: Change the addressed lines:
deletes the lines and replaces them with entered text.(.,.)d
: Deletes the addressed lines.e file
: Opens (edits) file.
Anything previously in the buffer is deleted.e !cmd
: Runs cmd with
/bin/sh, deletes everything in the buffer,
then fills the buffer with the output of the command.E file
: Like e
, but doesn't
warn before emptying the buffer.f file
: Sets the default filename to
file. If file is unspecified, prints
the current default filename.(1,$)g/re/cmds
: Applies the commands cmds
to those addressed lines that match the regex re.
Every command in cmds must be on a separate line,
with lines ending with a backslash \.
Default cmds is p
(print).(1,$)G/re/
: Interactively edit the addressed lines
matching the regex re: the line is printed and the
user is prompted for cmds, like in the g
command. &
repeats the last cmds
.H
: Toggles printing of error explanations.h
: Print explanation of last error.(.)i
: Insert text before the addressed line.
Current address is set to last line entered.(.,.+1)j
: Join addressed lines.(.)kc
: Mark line with lowercase letter
c.(.,.)l
: Prints addressed lines, with a
--More--
prompt if necessary.(.,.)m(.)
: Move lines in buffer.
The addressed lines are moved to after the
destination address parameter, which may be 0.(.,.)n
: Prints addressed lines with line numbers.(.,.)p
: Prints the addressed lines.P
: Toggles command prompt on or off.q
: Quits ed. Warns if there are unsaved changes
in the buffer.Q
: Quits ed without warning.($)r file
: Reads file to
after the addressed line.($)r !cmd
: Runs cmd with
/bin/sh and inserts its output to after the
addressed line.(.,.)s/re/repl/
: Replace text in the addressed lines
that matches the regex re with repl.
Only the first match in each line is replaced.
In repl an unescaped &
is replaced
with the matched text, and \1
to \9
is replaced with the 1st to 9th backreference in the matched
text. If repl is a single %
, the
replacement from the last s
-command is used.
repl may contain newlines if they are escaped
with a backslash \.(.,.)s/re/repl/g
and (.,.)s/re/repl/n
:
Like s/re/repl/
, but replaces either every
match of re (/g
) or the nth
match of re (/n
).(.,.)sngrp
: Repeat the last substitution.
ngrp is optional; they can be used to toggle
the n (n being a natural number), g, and
p flags of the substitution. r replaces the
substitution's regex with the regex of the previous search.(.,.)t(.)
: Copies (transfers) the addressed lines
to after the destination address parameter, which may be 0.u
: Undoes the last command. ed has only
a single undo level: u
is its own inverse.(1,$)v/re/cmds
: Like g/re/cmds
, but
applies cmds to those lines not matching
the regex re.(1,$)V/re/
: Like an interactive v/re/cmds
or an inverse G/re/
.(1,$)w file
: Writes addressed lines to
file. Anything previously in file is lost
without warning. If there is no previously set default
filename, sets the default filename file.
Uses the default filename if file is unspecified.(1,$)wq file
: Writes addressed lines
to file, then quits.(1,$)w !command
: Writes the addressed lines
to the standard input of command.(1,$)W file
: Like w
, but
appends to the end of file instead of
overwriting it.x
: in BSD ed, prompts for an encryption key.
In GNU ed, (.)x
copies the cut buffer to after
the addressed line.(.,.)y
: in GNU ed, yanks the addressed lines to
the cut buffer.(.+1)zn
: Scrolls n lines at a time,
starting at the addressed line.($)=
: Prints the line number of the
addressed line.(.+1)newline
: Prints the addressed line,
and sets the current address to that line.!command
: Executes command with
/bin/sh. If command starts with !, it is replaced
with the text of the previous !command. An unescaped
%
is replaced with the default filename.When in insert mode, a single . on a line on its own exits insert mode and puts the user in command mode.
Originally posted 2016-01-07 | Last changed 2017-06-10
Written in ed itself