sbase

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

ed.1 (9480B)


      1 .Dd December 31, 2025
      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 number of 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 The current address is set to the last line read.
    111 .It E Ar file
    112 As above,
    113 but without warning if the current buffer has unsaved changes.
    114 .It e Ar !command
    115 Delete the contents of the buffer and load in the output of
    116 .Ar command ,
    117 printing the number of bytes read to standard output.
    118 The remembered filename is not modified.
    119 The current address is set to the last line read.
    120 .It f Ar file
    121 Set the currently remembered filename to
    122 .Ar file
    123 , or print the currently remembered filename if
    124 .Ar file
    125 is omitted.
    126 .It (1,$)g/re/command
    127 Apply command to lines matching re.
    128 The dot is set to the matching line before command is executed.
    129 When each matching line has been operated on, the dot is set to the last line
    130 operated on.
    131 If no lines match then the dot remains unchanged.
    132 The command used may not be g, G, v, or V.
    133 .It (1,$)G/re/
    134 Interactively edit the range of line addresses that match re.
    135 The dot is set to the matching line and printed before a command is input.
    136 When each matching line has been operated on, the dot is set to the last line
    137 operated on.
    138 If no lines match then the dot remains unchanged.
    139 The command used may not be a, c, i, g, G, v, or V.
    140 .It h
    141 Print the reason for the most recent error.
    142 .It H
    143 Toggle error explanations.
    144 If on, the above behaviour is produced on all subsequent errors.
    145 .It (.)i
    146 Insert text into the buffer before the addressed line.
    147 The dot is set to the last line entered.
    148 If no text was entered, the dot is set to the addressed line
    149 .It (.,.+1)j
    150 Join two lines together.
    151 If only one address is given, nothing happens.
    152 The dot is set to the newly joined line.
    153 .It (.)kc
    154 Mark the line with the lower case character c. The dot is unchanged.
    155 .It (.,.)l
    156 Unambiguously print the addressed lines.
    157 The dot is set to the last line written.
    158 .It (.,.)m(.)
    159 Move lines in the buffer to the line address on the right hand side.
    160 An address of 0 on the right hand side moves to the start of the buffer.
    161 The dot is set to the last line moved.
    162 .It (.,.)n
    163 Print the addressed lines and their numbers.
    164 The dot is set to the last line printed.
    165 .It (.,.)p
    166 Print the addressed lines.
    167 The dot is set to the last line printed.
    168 .It P
    169 Toggle the prompt.
    170 Defaults to off, but is switched on if the -p flag is used.
    171 .It q
    172 Quit
    173 .Nm
    174 , warning if there are unsaved changes.
    175 .It Q
    176 As above, but without warning if the current buffer has unsaved changes.
    177 .It ($)r Ar file
    178 Read in
    179 .Ar file
    180 and append it to the current buffer at the addressed line,
    181 printing the number of bytes read to standard output.
    182 The currently remembered filename isn't changed unless it's empty.
    183 An address of 0 reads the
    184 .Ar file
    185 into the start of the buffer.
    186 .It ($)r Ar !command
    187 Execute the
    188 .Ar command
    189 and append its output in the current buffer at the addressed line,
    190 printing the number of bytes read to standard output.
    191 The currently remembered filename isn't changed.
    192 An address of 0 reads the output of
    193 .Ar command
    194 into the start of the buffer.
    195 .It (.,.)s/re/replacement/flags
    196 Substitute re for replacement in lines matching re.
    197 An & within replacement is replaced with the whole string matched by re.
    198 Backrefs can be used with the form \\n, where n is a positive non-zero integer.
    199 When % is the only character in replacement, it is substituted for the
    200 replacement string from the last substitute command.
    201 If a newline is part of replacement then the matched string is split into two
    202 lines; this cannot be done as part of a g or v command.
    203 If flags contains an integer n, then the nth match is replaced.
    204 If flags contains g, all matches are replaced.
    205 The dot is set to the last line matched.
    206 .It (.,.)t(.)
    207 As m, but copying instead of moving.
    208 The dot is set to the last line added.
    209 .It u
    210 Undo the last change.
    211 The dot is set to whatever it was before the undone command was performed.
    212 .It (1.$)v/re/command
    213 As with g, but operating on lines that don't match re.
    214 .It (1.$)V/re/
    215 As with G, but operating on lines that don't match re.
    216 .It (1,$)w Ar file
    217 Write the addressed lines to
    218 .Ar file
    219 , overwriting its previous contents if the file exists, and print the number of
    220 bytes written.
    221 If no filename is given the currently remembered filename will be used instead.
    222 The dot is unchanged.
    223 .It (1,$)W Ar file
    224 As above, but instead of overwriting the contents of
    225 .Ar file
    226 the addressed lines are appended to
    227 .Ar file
    228 instead.
    229 .It (1,$)w Ar !command
    230 Write the addressed lines to the standard input of
    231 .Ar command ,
    232 printing the number of bytes written to standard output.
    233 The dot is unchanged.
    234 .It (.+1)
    235 An address without a command prints the addressed line.
    236 Sets the dot to that line.
    237 .It (1,$)x Ar file
    238 Like the w command
    239 but after saving the
    240 .Ar file
    241 it exits with an exit status of 0
    242 independently of previous errors.
    243 .It (1,$)X Ar file
    244 Like the W command
    245 but after saving the
    246 .Ar file
    247 it exits with an exit status of 0
    248 independently of previous errors.
    249 .It (+) Ns Ic z Ns Ar n
    250 Scrolls
    251 .Ar n
    252 lines starting at the addressed line.
    253 If
    254 .Ar n
    255 is not specified then
    256 the value of $LINES - 1 is used.
    257 If the value of
    258 .Ar n
    259 is 0 or negative then the default value of 23 is used.
    260 .It ($)=
    261 Print the line number of the addressed line.
    262 The dot is unchanged.
    263 .It &
    264 Repeat the last command.
    265 .It ! Ar command
    266 Execute
    267 .Ar command
    268 using sh.
    269 If the first character of
    270 .Ar command
    271 is '!' then it is replaced with the text of the previous command.
    272 An unescaped % is replaced with the currently remembered filename.
    273 ! does not process escape characters.
    274 When
    275 .Ar command
    276 returns a '!' is printed.
    277 The dot is unchanged.
    278 .El
    279 .Sh ASYNCHRONOUS EVENTS
    280 .Bl -tag -width "SIGQUIT"
    281 .It Dv SIGHUP
    282 If the current buffer has changed since it was last written,
    283 .Nm
    284 attempts to write the buffer to the file
    285 .Pa ed.hup .
    286 Nothing is written to the currently remembered file, and
    287 .Nm
    288 exits.
    289 .It Dv SIGINT
    290 When an interrupt occurs,
    291 .Nm
    292 prints
    293 .Sq ?\en
    294 and returns to command mode.
    295 If interrupted during text input,
    296 the text already input is written to the current buffer,
    297 as if text input had been normally terminated.
    298 .It Dv SIGQUIT
    299 This signal is ignored.
    300 .El
    301 .Sh SEE ALSO
    302 .Xr sed 1 ,
    303 .Xr regexp 3
    304 .Rs
    305 .%A B. W. Kernighan
    306 .%T A Tutorial Introduction to the UNIX Text Editor
    307 .Re
    308 .Rs
    309 .Rs
    310 .%A B. W. Kernighan
    311 .%T Advanced Editing on UNIX
    312 .Re
    313 .Rs
    314 .%A B. W. Kernighan
    315 .%A P. J. Plauger
    316 .%B Software Tools
    317 .%O Addison-Wesley
    318 .%D 1976
    319 .Re
    320 .Rs
    321 .%A B. W. Kernighan
    322 .%A P. J. Plauger
    323 .%B Software Tools in Pascal
    324 .%O Addison-Wesley
    325 .%D 1981
    326 .Re
    327 .Sh STANDARDS
    328 POSIX.1-2013.
    329 Except where noted here:
    330 The command,
    331 .Cm z ,
    332 .Cm x ,
    333 and
    334 .Cm X
    335 are an extension to that specification.