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