User Tools

Site Tools


ed_cheat_sheet

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
ed_cheat_sheet [2023/07/01 00:19] – [ed Cheat Sheet] hc9ed_cheat_sheet [2023/07/01 00:20] (current) – [ed Cheat Sheet] hc9
Line 1: Line 1:
 +====== ed Cheat Sheet ======
 +ed:
 +  * ed is a small, powerful, line-oriented, command-line-interfaced text editor. All editors frustrate, but ed often amazes while others disappoint.
 +  * "If something goes wrong, ed is sometimes the only editor available. This is often the only time when it is used interactively." --from its [[wp>ed_(text_editor)| Wikipedia entry]]
 +  * [[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//<sup>*</sup>]'' | Edit //file//. | ''E [//file//<sup>*</sup>]'' | Edit, discarding changes. |
 +| ''($)r [//file//]'' | Read and append. | ''f [//file//]'' | Set/display file name. |
 +| ''(1,$)w [//file//<sup>*</sup>]'' | Write. | ''(1,$)W [//file//<sup>*</sup>]'' | Append to //file//. |
 +| ''(1,$)wq [//file//<sup>*</sup>]'' | Write and quit. |
 +
 +| <sup>*</sup> | 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. |
 +
 +----
 +[[http://sdf.org/?tutorials/ed|ed Cheat Sheet]] - traditional link (using [[wp>Revision_Control_System|RCS]])
  
ed_cheat_sheet.txt · Last modified: 2023/07/01 00:20 by hc9