Contents

  1. Prelude
  2. Introduction
  3. Ed Basics
  4. Advanced Editting
  5. More Advanced Commands and Related Shortcuts
  6. Searching Files
  7. Extra Commands


  1. A Prelude:

    The below is a help file for ed. The editor used inside the mud to edit files. This was borrowed and modified from a forgotten source, if anyone knows the original author, or where I stumbled upon this on the web, i would appreciate knowing so that I can give the proper credit. Zifnab@reddragon

    (How to read the notation in this document)

    In all examples:

    Words in angle brackets < like this > are not to be typed literally, but rather to be substituted for.

    For example: '< number >p' could be '4p', '3p','100p' etc.

    Anything in square brackets [] is optional.

    < x|y > reperesents < x > _OR_ < y >, but not both.

    : is the standard ed prompt.


  2. Introduction
    Once you are in ed, your prompt will become ':' (command mode). From this prompt you enter ed commands (thats why its called command mode).

    There are 2 modes to ed, 'command mode' and 'insert mode'. When you are in command mode ed is waiting for you to enter commands, such as deleteing rows, displaying rows etc. When in command mode, everything you type gets treated as a command.

    In insert mode your prompt may or may not be the line number you are on depending on your settings. ( I will explain more on that shortly). When you are in insert mode everything you type gets 'put into' the file you are editting.


  3. Ed Basics ('a', 'c', 'd', 'i', 'l', 'p', 'w', 'z', and '=' commands.)


    An example encompassing what we've done so far:
    > ed a                    -> filename a
    :a                        -> command 'a' for append
    This is line 1.           -> the next 5 lines are entering the file.
    This is line @.
    This is line 3.
    This is line 5.
    This is too many lines.
    .                         -> return to command mode.
    :1,3p                     -> display the lines 1 - 3
    This is line 1.
    This is line @.
    This is line 3.
    :=                        ->display current line number
    3                         ->current line number
    :5l                       -> using the 'l' command to show line feed on line 5
    This is too many lines.$
    :5d                       -> delete line 5
    :1,$p                     -> print from line 1 to end of the file
    This is line 1.
    This is line @.
    This is line 3.
    This is line 5.
    :2c                       -> change line 2
    This is a line 2.
    .                         -> back to command mode
    :1z                       -> print from line 1 down 20 lines
    This is line 1.
    This is line 2.
    This is line 3.
    This is line 5.
    :4i                        -> insert above line 4 (now in insert mode)
    This is line 4.
    .                          -> back to command mode.
    :1,$p                      -> print from 1 to end of file
    This is line 1.
    This is line 2.
    This is line 3.
    This is line 4.
    This is line 5.
    :w file.txt                -> save our file
    :q                         -> quit
    
    

  4. Advanced Editing (The 's' command)

    The 's' command is used for substitutions. The general format is this:

    :[ < number1 > [,< number2 > ]]s < delim > < pattern > < delim > < sub > [ < delim > gp]

    The command may look intimidating at first, but it turns out to be one of the most powerful commands in ed.

    An explanation of all the angle-brackets:

    < number1 > and < number2 > are the range of substitution. If ',< number2 >' is omitted, the range of effect is merely line < number1 >. If '< number1 >' is also omitted, the substitution defaults to the present line.

    < delim > is simply a character used as a separator. Care should be taken that '< delim >' does not occur in either < pattern > or < sub >. The most common choices for < delimiter > are '/' and '!', although any character can be used.

    < pattern > is the string that will be changed. < sub > is the string that it will be changed to. If < pattern > begins with a '^', that is taken to mean 'beginning of line.' Similarly, if it ends with '$', it signifies 'end of line.'

    The final optional [gp] are used, respectively, to make the substitution global throughout the line (instead of just affecting the first occurrence), and to display the newly-changed line immediately afterwards. Note that g must come before p, if both are used.

    Some examples:
    
    :.
    This is line nubmer 3.
    :s/bm/mb/p        <--- Note that '/' is used as the delimiter here.
                           we want to replace the first occurence of bm with mb
                           and print the line afterwords
    This is line number 3.
    :
    
    :.
    Thsi si line 3.
    :s!si!is!p        <--- The delimiter here is '!'.
    This si line 3.   <--- Note that only the 1st occurrence of 'si' was changed
    :
    
    :.
    Thsi si line number 3.
    :s!si!is!gp       <--- Here, the delimiter is '!', again. and because we used
                           the g parameter all occurences of si were changed.
    This is line number 3.
    :
    
    :3,5p
    This is lize 3.
    This is lize 4.
    This is lize 5.
    :3,5sqzqnqp      <--- Here, to confuse matters, the delimiter is 'q'.
                          and we changed a range of lines 3-5
    This is line 3.
    This is line 4.
    This is line 5.
    :
    
    General notes:

    For a global substitution, use:

    :1,$s/< pattern>/< sub >/g

    Beware of special characters in < pattern>. '.', '(', ')', '&', '*', '|', '[', '^', and ']' should all be prepended by backslashes ('\') if they are used. '\' is, although possible to use in < sub > and < pattern >, very tricky to use. The author recommends beginners use the 'c' command to do substitutions for this character instead. If you really want to below is an example of a few ways to do do this.

    wiz/magneto -> we want to change this line to domain :s.wiz/magneto.domain -> notice by switching delimiters you can put a / in the pattern. if you use / as the delimiter, this will not work :s/wiz\/magneto/domain -> the other option is to escape the / with a \

    Some of these special characters that can be used in <pattern>:

    .       Match any character.
    x*      Match any numbers of x (0 or more).
    [abc]   Match 'a', 'b' or 'c'.
    [0-9]   Match any digit 0 - 9.
    [a-z]   Match any lowercase letter.
    [^0-9]  Match anything except a digit 0 - 9.
    
    The & can be used in the replacement to represent the text being replaced.
    
    Example:
    :.
    This is a lazy line, lying abed.  It is also silly; abcd.
    :s/ab.d/ABCD/gp
    This is a lazy line, lying ABCD.  It is also silly; ABCD.
    :
    
    Example:
    :.
    This is a long line that is being used to demonstrate a silly example.
    :s/l.n./&foo/
    This is a longfoo linefoo that is being used to demonstrate a silly example.
     Author's Interjection:
     (The '< range >' notation)
    
     What was formerly referred to as < number1 >,< number2 > < command > will, 
     from here on out, be referred to as < range > < commmand >, for the 
     author's typing ease. 
    
     Thank you.
    

  5. Still More Advanced Commands, and Related Shortcuts (The 'j', 'Q', 'm','t', 'x', and '!' commands)

  6. Searching files (The 'g', 'v', '?', and '/' commands)