DEV Community

Cover image for Ed Cheat Sheet

Posted on • Originally published at on

Ed Cheat Sheet

What's Ed?

This post is not intended as a general introduction to Ed however the essentials you may need to know are that:

  • Ed was the text editor written by Ken Thompson while initially developing Unix.
  • It is famed for its terseness, often giving no error messages or any form of communication to the user at all.
  • With just a few commands you can probably match the speed you work in in your regular text editor.

A more general view of Ed can be found here.

Cheat Sheet

Note that X and Y are used to indicate user-given values.
FILE is used to indicate a user-given filename.

Single Commands

Command Description
(Any number) Set current line to given value if line exists.
P Display prompt.
p Print current line.
n Same as 'p' but print with line numbers.
H Display verbose errors.
a Append : insert new line and start editing.
i Insert: start editing on line above current line.
c Replace current line.
w Write (save) file
z Print as much of the file as will fit on the screen. Set current line as last visible line.
l Place a $ at the end of a command to show where a line ends, useful for showing trailing white space.
u Undo last command.
$ Go to last line of file.
+ Go to next line.
- Go to previous line.
= Current line number.
. Exit edit mode.
, Symbol that indicates the entire file.
; Current line to end of file.

Compound Commands

Command Description
wq Write and quit.
,p Print whole file to screen.
,n Print current line with line number.
XmY Move line X and insert it after line Y.
,np Print numbered listing of all lines.
XzY Starting on line X, print the next Y lines.
Xd Delete line X.
Xr FILE Read a file in and insert it at line X.
X,Yj Join line X to Y.
XtY Copy line X to Y.
XW FILE Append line X to another file.
X,YW FILE Append lines X through Y to another file.
f X When saving the file, save it as X (effectively a save as option).
e X Switch to editing file X.
E X Force switch to other file without checking if current file has been saved.
X,Yw FILE Save the text between lines X and Y to another file.
!X Run command X outside of ed and return.
!! Run previous external command again.
r !X Read external command X into the current file.
w !X Write your current program to another file/program. This functions similarly to Unix Pipes.
kX Assign a bookmark called X. Bookmarks can only be assigned to the current line.
'X Go to bookmark X.
/X/ Search for X on current line.
g/X/p Search for X on all lines and print matching lines.
g/X/np Search for X on all lines and print matching lines with line numbers.
$= Print last line number.
.= Display current line number.

Discussion (0)