sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

ed.1 (7418B)


      1 .Dd December 27, 2016
      2 .Dt ED 1
      3 .Os sbase
      4 .Sh NAME
      5 .Nm ed
      6 .Nd text editor
      7 .Sh SYNOPSIS
      8 .Nm
      9 .Op Fl s
     10 .Op Fl p Ar string
     11 .Op Ar file
     12 .Sh DESCRIPTION
     13 .Nm
     14 is the standard text editor.
     15 It performs line-oriented operations on a buffer; The buffer's contents are
     16 manipulated in command mode and text is written to the buffer in input mode.
     17 Command mode is the default.
     18 To exit input mode enter a dot ('.') on a line of its own.
     19 .Pp
     20 If
     21 .Nm
     22 is invoked with a file as an argument, it will simulate an edit command and read
     23 the file's contents into a buffer.
     24 Changes to this buffer are local to
     25 .Nm
     26 until a write command is given.
     27 .Pp
     28 .Nm
     29 uses the basic regular expression syntax and allows any character but space and
     30 newline to be used as a delimiter in regular expressions.
     31 .Sh OPTIONS
     32 .Bl -tag -width Ds
     33 .It Fl s
     34 Suppress diagnostic messages
     35 .It Fl p Ar string
     36 Use
     37 .Ar string
     38 as a prompt when in command mode
     39 .El
     40 .Sh EXTENDED DESCRIPTION
     41 .Ss Addresses
     42 Commands operate on addresses.
     43 Addresses are used to refer to lines within the buffer.
     44 Address ranges may have spaces before and after the separator.
     45 Unless otherwise specified, 0 is an invalid address.
     46 The following symbols are valid addresses:
     47 .Bl -tag -width Ds
     48 .It n
     49 The nth line.
     50 .It .
     51 The current line, or "dot".
     52 .It $
     53 The last line.
     54 .It +
     55 The next line.
     56 .It +n
     57 The nth next line.
     58 .It ^ or -
     59 The previous line.
     60 .It ^n or -n
     61 The nth previous line.
     62 .It x,y
     63 The range of lines from x to y.
     64 The default value of x is 1, and the default value of y is $.
     65 .It x;y
     66 As above, except that the current line is set to x.
     67 Omitting x in this case uses the current line as the default value.
     68 .It /re/
     69 The next line matching re.
     70 .It ?re?
     71 The last line matching re.
     72 .It 'c
     73 The line marked by c. See k below.
     74 .El
     75 .Ss Commands
     76 .Nm
     77 expects to see one command per line, with the following exception: commands may
     78 be suffixed with either a list, number, or print command.
     79 These suffixed commands are run after the command they're suffixed to has
     80 executed.
     81 .Pp
     82 The following is the list of commands that
     83 .Nm
     84 knows about.
     85 The parentheses contain the default addresses that a command uses.
     86 .Bl -tag -width Ds
     87 .It (.)a
     88 Append text after the addressed line.
     89 The dot is set to the last line entered.
     90 If no text was entered, the dot is set to the addressed line.
     91 An address of 0 appends to the start of the buffer.
     92 .It (.,.)c
     93 Delete the addressed lines and then accept input to replace them.
     94 The dot is set to the last line entered.
     95 If no text was entered, the dot is set to the line before the deleted lines.
     96 .It (.,.)d
     97 Delete the addressed lines.
     98 If there is a line after the deleted range, the dot is set to it.
     99 Otherwise, the dot is set to the line before the deleted range.
    100 .It e Ar file
    101 Delete the contents of the buffer and load in
    102 .Ar file
    103 for editing, printing the bytes read to standard output.
    104 If no filename is given,
    105 .Nm
    106 uses the currently remembered filename.
    107 The remembered filename is set to
    108 .Ar file
    109 for later use.
    110 .It E Ar file
    111 As above, but without warning if the current buffer has unsaved changes.
    112 .It f Ar file
    113 Set the currently remembered filename to
    114 .Ar file
    115 , or print the currently remembered filename if
    116 .Ar file
    117 is omitted.
    118 .It (1,$)g/re/command
    119 Apply command to lines matching re.
    120 The dot is set to the matching line before command is executed.
    121 When each matching line has been operated on, the dot is set to the last line
    122 operated on.
    123 If no lines match then the dot remains unchanged.
    124 The command used may not be g, G, v, or V.
    125 .It (1,$)G/re/
    126 Interactively edit the range of line addresses that match re.
    127 The dot is set to the matching line and printed before a command is input.
    128 When each matching line has been operated on, the dot is set to the last line
    129 operated on.
    130 If no lines match then the dot remains unchanged.
    131 The command used may not be a, c, i, g, G, v, or V.
    132 .It h
    133 Print the reason for the most recent error.
    134 .It H
    135 Toggle error explanations.
    136 If on, the above behaviour is produced on all subsequent errors.
    137 .It (.)i
    138 Insert text into the buffer before the addressed line.
    139 The dot is set to the last line entered.
    140 If no text was entered, the dot is set to the addressed line
    141 .It (.,.+1)j
    142 Join two lines together.
    143 If only one address is given, nothing happens.
    144 The dot is set to the newly joined line.
    145 .It (.)kc
    146 Mark the line with the lower case character c. The dot is unchanged.
    147 .It (.,.)l
    148 Unambiguously print the addressed lines.
    149 The dot is set to the last line written.
    150 .It (.,.)m(.)
    151 Move lines in the buffer to the line address on the right hand side.
    152 An address of 0 on the right hand side moves to the start of the buffer.
    153 The dot is set to the last line moved.
    154 .It (.,.)n
    155 Print the addressed lines and their numbers.
    156 The dot is set to the last line printed.
    157 .It (.,.)p
    158 Print the addressed lines.
    159 The dot is set to the last line printed.
    160 .It P
    161 Toggle the prompt.
    162 Defaults to off, but is switched on if the -p flag is used.
    163 .It q
    164 Quit
    165 .Nm
    166 , warning if there are unsaved changes.
    167 .It Q
    168 As above, but without warning if the current buffer has unsaved changes.
    169 .It ($)r Ar file
    170 Read in
    171 .Ar file
    172 and append it to the current buffer, printing the bytes read to standard output.
    173 The currently remembered filename isn't changed unless it's empty.
    174 An address of 0 reads the file into the start of the buffer.
    175 .It (.,.)s/re/replacement/flags
    176 Substitute re for replacement in lines matching re.
    177 An & within replacement is replaced with the whole string matched by re.
    178 Backrefs can be used with the form \\n, where n is a positive non-zero integer.
    179 When % is the only character in replacement, it is substituted for the
    180 replacement string from the last substitute command.
    181 If a newline is part of replacement then the matched string is split into two
    182 lines; this cannot be done as part of a g or v command.
    183 If flags contains an integer n, then the nth match is replaced.
    184 If flags contains g, all matches are replaced.
    185 The dot is set to the last line matched.
    186 .It (.,.)t(.)
    187 As m, but copying instead of moving.
    188 The dot is set to the last line added.
    189 .It u
    190 Undo the last change.
    191 The dot is set to whatever it was before the undone command was performed.
    192 .It (1.$)v/re/command
    193 As with g, but operating on lines that don't match re.
    194 .It (1.$)V/re/
    195 As with G, but operating on lines that don't match re.
    196 .It (1,$)w Ar file
    197 Write the addressed lines to
    198 .Ar file
    199 , overwriting its previous contents if the file exists, and print the number of
    200 bytes written.
    201 If no filename is given the currently remembered filename will be used instead.
    202 The dot is unchanged.
    203 .It (1,$)W Ar file
    204 As above, but instead of overwriting the contents of
    205 .Ar file
    206 the addressed lines are appended to
    207 .Ar file
    208 instead.
    209 .It (.+1)
    210 Print the addressed line.
    211 Sets the dot to that line.
    212 .It ($)=
    213 Print the line number of the addressed line.
    214 The dot is unchanged.
    215 .It &
    216 Repeat the last command.
    217 .It ! Ar command
    218 Execute
    219 .Ar command
    220 using sh.
    221 If the first character of
    222 .Ar command
    223 is '!' then it is replaced with the text of the previous command.
    224 An unescaped % is replaced with the currently remembered filename.
    225 ! does not process escape characters.
    226 When
    227 .Ar command
    228 returns a '!' is printed.
    229 The dot is unchanged.
    230 .El
    231 .Sh SEE ALSO
    232 .Xr sed 1 ,
    233 .Xr regexp 3
    234 .Sh STANDARDS
    235 The
    236 .Nm
    237 utility is compliant with the
    238 .St -p1003.1-2013
    239 specification, except where noted here:
    240 g and v operate on single commands rather than lists delimited with '\\'.
    241 e, E, r, w, and W commands cannot accept shell escapes.