You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
5.0 KiB

<h1>ed Cheat Sheet</h1>
<p>ed is a small, powerful, line-oriented, command-line-interfaced
text editor. All editors frustrate, but ed often amazes while
others disappoint.
</p>
<p><a href="http://www.gnu.org/fun/jokes/ed.msg.html">ed, man! !man
ed</a> &#8212; ed is the standard text editor.
</p>
<p><code>man ed</code> for more information.</p>
<p>Start ed from your shell command line:</p>
<code style="margin-left: 10%;">ed <em>file</em></code>
<p>Edit file by entering ed commands with the following syntax:</p>
<code style="margin-left: 10%;">[<em>range</em>][<em>command</em>]</code>
<p><em>range</em> specifies the line or block of consecutive lines
(syntax: <code><em>from-line</em>,<em>to-line</em></code>)
to which <em>command</em> is applied. Default range is the
current line except where noted below with a parenthesis
preceding the command syntax. Lines are specified as follows:
</p>
<table border="1">
<tr>
<td style="width: 5%;"><em>n</em></td><td style="width: 20%">line <em>n</em></td style="width: 5%;">
<td style="width: 5%;"><tt>.</tt></td><td style="width: 20%">current</td>
<td style="width: 5%;"><tt>$</tt></td><td style="width: 20%">last</td>
<td style="width: 5%;"><tt>'</tt><em>c</em></td><td style="width: 20%">mark <em>c</em> </td>
</tr>
<tr>
<td><tt>-</tt>[<em>n</em>]</td><td>up <em>n</em> (default: 1)</td>
<td><tt>+</tt>[<em>n</em>]</td><td>down <em>n</em> (default: 1)</td>
<td><tt>,</tt></td><td>1,$</td>
<td><tt>;</tt></td><td>.,$</td>
</tr>
<tr>
<td><code>?<em>re</em>?</code></td><td colspan="3">previous regexp match</td>
<td><code>/<em>re</em>/</code></td><td colspan="3">next regexp match</td>
</tr>
</table>
<h2>Input commands</h2>
<table border="1">
<tr>
<td style="width: 3%;"><tt>a</tt></td><td style="width: 22%">Append
after.</tt></td>
<td style="width: 3%;"><tt>c</tt></td><td style="width: 22%">Change range.</td>
<td style="width: 3%;"><tt>i</tt></td><td style="width: 22%">Insert
before.</tt></td>
<td style="width: 3%;"><tt>.</tt></td><td style="width: 22%">End input mode.</td>
</tr>
</table>
<h2>Edit commands</h2>
<table border="1">
<tr>
<td style="width: 10%;"><code>d</code></td><td style="width: 40%;">Delete.</td>
<td style="width: 10%;"><code>s/<em>re</em>/<em>s</em>/[g|<em>n</em>][p]</code></td><td style="width: 40%;">Substitute.
</tr>
<tr>
<td><code>m[<em>line</em>]</code></td><td>Move after <em>line</em>.</td>
<td><code>t[<em>line</em>]</code></td><td>Copy after <em>line</em>.</td>
</tr>
<tr>
<td><code>(.,+)j</code></td><td>Join lines.</td>
<td><code>u</code></td><td>Undo.</td>
</tr>
<tr>
<td><code>(1,$)g/<em>re</em>/<em>cmds</em></code></td><td>Perform <em>cmds</em> for all matching lines.</td>
<td><code>(1,$)v/<em>re</em>/<em>cmds</em></code></td><td>Perform <em>cmds</em> for all non-matching lines.</td>
</tr>
</table>
<h2>File commands</h2>
<table border="1">
<tr>
<td style="width: 20%;"><code>e [<em>file</em><sup>*</sup>]</code></td><td style="width: 30%;">Edit <em>file</em>.</td>
<td style="width: 20%;"><code>E [<em>file</em><sup>*</sup>]</code></td><td style="width: 30%;">Edit, discarding changes.</td>
</tr>
<tr>
<td><code>($)r [<em>file</em>]</code></td><td>Read and append.</td>
<td><code>f [<em>file</em>]</code></td><td>Set/display file name.</td>
</tr>
<tr>
<td><code>(1,$)w [<em>file</em><sup>*</sup>]</code></td><td>Write.</td>
<td><code>(1,$)W [<em>file</em><sup>*</sup>]</code></td><td>Append to <em>file</em>.</td>
</tr>
<tr>
<td><code>(1,$)wq [<em>file</em><sup>*</sup>]</code></td><td>Write and quit.</td>
</tr>
</table>
<table>
<tr>
<td style="vertical-align: top;"><sup>*</sup></td>
<td>In place of <em>file</em>, specify
"<tt>!</tt><em>shell-command</em>" to read/write text to
<em>shell-command</em> standard output/input.
</td>
</tr>
</table>
<h2>Display commands</h2>
<table border="1">
<tr>
<td style="width: 10%;"><code>p</code></td><td style="width: 20%;">List lines.</td>
<td style="width: 10%;"><code>l</code></td><td style="width: 20%;">&hellip; with unprintables.</td>
<td style="width: 10%;"><code>n</code></td><td style="width: 20%;">&hellip; with numbers.</td>
</tr>
<tr>
<td><code>(+)z[<em>lines</em>]</code></td><td>Scroll.</td>
<td><code>(+)<em>null</em></code></td><td><tt>p</tt></td>
</tr>
</table>
<h2>Other commands</h2>
<table border="1">
<tr>
<td style="width: 10%;"><code>k<em>c</em></code></td><td style="width: 20%;">Mark line.</td>
<td style="width: 3%;"><code>($)=</code></td><td style="width: 27%;">Display line number.</td>
<td style="width: 3%;"><code>h</code></td><td style="width: 27%;">Last error text.</td>
</tr>
<tr>
<td><code>!<em>shell-command</em></code></td><td>Execute <em>shell-command</em>.</td>
<td><code>q</code></td><td>Quit.</td>
<td><code>Q</code></td><td>Quit, discarding changes.</td>
</tr>
</table>
<hr/>
<cite>$Id: ed.html,v 1.5 2007/10/09 00:27:11 papa Exp $</cite>