| 1 | .TH EDIT UCB 4/8/79 UCB |
| 2 | .SH NAME |
| 3 | edit \- text editor (variant of the ex editor for new or casual users) |
| 4 | .SH SYNOPSIS |
| 5 | .B edit |
| 6 | [ |
| 7 | .B \-r |
| 8 | ] |
| 9 | name ... |
| 10 | .SH DESCRIPTION |
| 11 | .I Edit |
| 12 | is a variant of the text editor |
| 13 | .I ex |
| 14 | recommended for new or casual users who wish to use a command oriented editor. |
| 15 | The following brief introduction should help you get started with |
| 16 | .I edit. |
| 17 | A more complete basic introduction is provided by |
| 18 | .I "Edit: A tutorial". |
| 19 | A |
| 20 | .I "Ex/edit command summary (version 2.0)" |
| 21 | is also very useful. |
| 22 | See |
| 23 | .IR ex (UCB) |
| 24 | for other useful documents; |
| 25 | in particular, if you are using a \s-2CRT\s0 terminal you will want |
| 26 | to learn about the display editor |
| 27 | .I vi. |
| 28 | .SH "BRIEF INTRODUCTION" |
| 29 | To edit the contents of an existing file you begin with the command |
| 30 | ``edit name'' to the shell. |
| 31 | .I Edit |
| 32 | makes a copy of the file which you can then edit, and tells you how |
| 33 | many lines and characters are in the file. |
| 34 | To create a new file, just make up a name for the file and try to run |
| 35 | .I edit |
| 36 | on it; you will cause an error diagnostic, but don't worry. |
| 37 | .PP |
| 38 | .I Edit |
| 39 | prompts for commands with the character `:', which you should see after |
| 40 | starting the editor. |
| 41 | If you are editing an existing file, then you will have some lines in |
| 42 | .I edit's |
| 43 | buffer (its name for the copy of the file you are editing). |
| 44 | Most commands to |
| 45 | .I edit |
| 46 | use its ``current line'' if you don't tell them which line to use. |
| 47 | Thus if you say |
| 48 | .B print |
| 49 | (which can be abbreviated \fBp\fR) |
| 50 | and hit carriage return (as you should after all |
| 51 | .I edit |
| 52 | commands) this current line will be printed. |
| 53 | If you |
| 54 | .B delete |
| 55 | (\fBd\fR) the current line, |
| 56 | .I edit |
| 57 | will print the new current line. |
| 58 | When you start editing, |
| 59 | .I edit |
| 60 | makes the last line of the file the current line. |
| 61 | If you |
| 62 | .B delete |
| 63 | this last line, then the new last line becomes the current one. |
| 64 | In general, after a |
| 65 | .B delete, |
| 66 | the next line in the file becomes the current line. |
| 67 | (Deleting the last line is a special case.) |
| 68 | .PP |
| 69 | If you start with an empty file, or wish to add some new lines, then the |
| 70 | .B append |
| 71 | (\fBa\fR) |
| 72 | command can be used. |
| 73 | After you give this command (typing a carriage return after the |
| 74 | word \fBappend\fR) |
| 75 | .I edit |
| 76 | will read lines from your terminal until you give a line consisting |
| 77 | of just a ``\fB.\fR'', placing these lines after the current line. |
| 78 | The last line you type then becomes the current line. |
| 79 | The command |
| 80 | .B insert |
| 81 | (\fBi\fR) |
| 82 | is like |
| 83 | .B append |
| 84 | but places the lines you give before, rather than after, the current line. |
| 85 | .PP |
| 86 | .I Edit |
| 87 | numbers the lines in the buffer, with the first line having number 1. |
| 88 | If you give the command |
| 89 | ``1'' |
| 90 | then |
| 91 | .I edit |
| 92 | will type this first line. |
| 93 | If you then give the command |
| 94 | .B delete |
| 95 | .I edit |
| 96 | will delete the first line, and line 2 will become line 1, and |
| 97 | .I edit |
| 98 | will print the current line (the new line 1) so you can see where you are. |
| 99 | In general, the current line will always be the last line affected by a command. |
| 100 | .PP |
| 101 | You can make a change to some text within the current line by using the |
| 102 | .B substitute |
| 103 | (\fBs\fR) |
| 104 | command. |
| 105 | You say ``s/\fIold\fR\|/\fInew\fR/'' where |
| 106 | .I old |
| 107 | is replaced by the old characters you want |
| 108 | to get rid of and |
| 109 | .I new |
| 110 | is the new characters you want to replace it with. |
| 111 | .PP |
| 112 | The command |
| 113 | .B file |
| 114 | (\fBf\fR) will tell you how many lines there are in the buffer you are editing |
| 115 | and will say ``[Modified]'' if you have changed it. |
| 116 | After modifying a file you can put the buffer text back to replace the file |
| 117 | by giving a |
| 118 | .B write |
| 119 | (\fBw\fR) |
| 120 | command. |
| 121 | You can then leave the editor by issuing a |
| 122 | .B quit |
| 123 | (\fBq\fR) |
| 124 | command. |
| 125 | If you run |
| 126 | .I edit |
| 127 | on a file, but don't change it, it is not necessary |
| 128 | (but does no harm) |
| 129 | to |
| 130 | .B write |
| 131 | the file back. |
| 132 | If you try to |
| 133 | .B quit |
| 134 | from |
| 135 | .I edit |
| 136 | after modifying the buffer without writing it out, you will be warned that |
| 137 | there has been ``No \fBwrite\fR since last change'' and |
| 138 | .I edit |
| 139 | will await another command. |
| 140 | If you wish not to |
| 141 | .B write |
| 142 | the buffer out then you can issue another |
| 143 | .B quit |
| 144 | command. |
| 145 | The buffer is then irretrievably discarded, and you return to the shell. |
| 146 | .PP |
| 147 | By using the |
| 148 | .B delete |
| 149 | and |
| 150 | .B append |
| 151 | commands, |
| 152 | and giving line numbers to see lines in the file you can make any |
| 153 | changes you desire. |
| 154 | You should learn at least a few more things, however, if you are to use |
| 155 | .I edit |
| 156 | more than a few times. |
| 157 | .PP |
| 158 | The |
| 159 | .B change |
| 160 | (\fBc\fR) |
| 161 | command will change the current line to a sequence of lines you supply |
| 162 | (as in |
| 163 | .B append |
| 164 | you give lines up to a line consisting of only a ``.''). |
| 165 | You can tell |
| 166 | .B change |
| 167 | to change more than one line by giving the line numbers of the |
| 168 | lines you want to change, i.e. ``3,5change''. |
| 169 | You can print lines this way too. |
| 170 | Thus ``1,23p'' prints the first 23 lines of the file. |
| 171 | .PP |
| 172 | The |
| 173 | .B undo |
| 174 | (\fBu\fR) |
| 175 | command will reverse the effect of the last command you gave which changed |
| 176 | the buffer. |
| 177 | Thus if give a |
| 178 | .B substitute |
| 179 | command which doesn't do what you want, you can say |
| 180 | .B undo |
| 181 | and the old contents of the line will be restored. |
| 182 | You can also |
| 183 | .B undo |
| 184 | an |
| 185 | .B undo |
| 186 | command so that you can continue to change your mind. |
| 187 | .I Edit |
| 188 | will give you a warning message when commands you do affect more than |
| 189 | one line of the buffer. |
| 190 | If the amount of change seems unreasonable, you should consider doing |
| 191 | an |
| 192 | .I undo |
| 193 | and looking to see what happened. |
| 194 | If you decide that the change is ok, then you can |
| 195 | .I undo |
| 196 | again to get it back. |
| 197 | Note that commands such as |
| 198 | .I write |
| 199 | and |
| 200 | .I quit |
| 201 | cannot be undone. |
| 202 | .PP |
| 203 | To look at the next line in the buffer you can just hit carriage return. |
| 204 | To look at a number of lines hit ^D (control key and, while it is |
| 205 | held down D key, then let up both) rather than carriage return. |
| 206 | This will show you a half screen of lines on a CRT or 12 lines on a hardcopy |
| 207 | terminal. |
| 208 | You can look at the text around where you are by giving the command ``z.''. |
| 209 | The current line will then be the last line printed; you can get back |
| 210 | to the line where you were before the ``z.'' command by saying ``\'\'''. |
| 211 | The |
| 212 | .B z |
| 213 | command can also be given other following characters ``z\-'' prints |
| 214 | a screen of text (or 24 lines) ending where you are; |
| 215 | ``z+'' prints the next screenful. |
| 216 | If you want less than a screenful of lines do, e.g., ``z.12'' to get |
| 217 | 12 lines total. |
| 218 | This method of giving counts works in general; |
| 219 | thus you can delete 5 lines starting with the current line with the command |
| 220 | ``delete 5''. |
| 221 | .PP |
| 222 | To find things in the file you can use line numbers if you happen to know |
| 223 | them; since the line numbers change when you insert and delete lines |
| 224 | this is somewhat unreliable. |
| 225 | You can search backwards and forwards in the file for strings by giving |
| 226 | commands of the form |
| 227 | \fB/text/\fR |
| 228 | to search forward for |
| 229 | .I text |
| 230 | or |
| 231 | \fB?text?\fR |
| 232 | to search backward for |
| 233 | .I text. |
| 234 | If a search reaches the end of the file without finding the text it |
| 235 | wraps, end around, and continues to search back to the line where you are. |
| 236 | A useful feature here is a search of the form |
| 237 | \fB/^text/\fR |
| 238 | which searches for |
| 239 | .I text |
| 240 | at the beginning of a line. |
| 241 | Similarly |
| 242 | \fB/text$/\fR |
| 243 | searches for |
| 244 | .I text |
| 245 | at the end of a line. |
| 246 | You can leave off the trailing / or ? in these commands. |
| 247 | .PP |
| 248 | The current line has a symbolic name ``\fB.\fR''; this is most |
| 249 | useful in a range of lines as in ``.,$print'' which prints the rest of |
| 250 | the lines in the file. |
| 251 | To get to the last line in the file you can refer to it by its symbolic |
| 252 | name ``$''. |
| 253 | Thus the command ``$ delete'' or ``$d'' deletes the last line in the |
| 254 | file, no matter which line was the current line before. |
| 255 | Arithmetic with line references is also possible. |
| 256 | Thus the line ``$\-5'' is the fifth before the last, and |
| 257 | ``.+20'' is 20 lines after the present. |
| 258 | .PP |
| 259 | You can find out which line you are at by doing |
| 260 | ``.=''. |
| 261 | This is useful if you wish to move or copy a section of text within a file or |
| 262 | between files. |
| 263 | Find out the first and last line numbers you wish to copy or move (say 10 to 20). |
| 264 | For a move you can then say |
| 265 | ``10,20move "a'' |
| 266 | which deletes these lines from the file and places them in a buffer named |
| 267 | .I a. |
| 268 | .I Edit |
| 269 | has 26 such buffers named |
| 270 | .I a |
| 271 | through |
| 272 | .I z. |
| 273 | You can later get these lines back by doing |
| 274 | ``"a move \fB.\fR'' |
| 275 | to put the contents of buffer |
| 276 | .I a |
| 277 | after the current line. |
| 278 | If you want to move or copy these lines between files you can give an |
| 279 | .B edit |
| 280 | (\fBe\fR) |
| 281 | command after copying the lines, following it with the name of the other |
| 282 | file you wish to edit, i.e. ``edit chapter2''. |
| 283 | By changing |
| 284 | .I move |
| 285 | to |
| 286 | .I copy |
| 287 | above you can get a pattern for copying lines. |
| 288 | If the text you wish to move or copy is all within one file |
| 289 | then you can just say |
| 290 | ``10,20move $'' |
| 291 | for example. |
| 292 | It is not necessary to use named buffers in this case (but you can if you wish). |
| 293 | .SH SEE\ ALSO |
| 294 | ex (UCB), vi (UCB), |
| 295 | `Edit: A tutorial', by Ricki Blau and James Joyce |
| 296 | .SH AUTHOR |
| 297 | William Joy |
| 298 | .SH BUGS |
| 299 | See |
| 300 | .IR ex (UCB). |