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