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