Commit | Line | Data |
---|---|---|
47d38f87 BJ |
1 | .de ZP |
2 | .nr pd \\n()P | |
3 | .nr )P 0 | |
4 | .if \\n(.$=0 .IP | |
5 | .if \\n(.$=1 .IP "\\$1" | |
6 | .if \\n(.$>=2 .IP "\\$1" "\\$2" | |
7 | .nr )P \\n(pd | |
8 | .rm pd | |
9 | .. | |
10 | .de LC | |
11 | .br | |
12 | .sp .1i | |
13 | .ne 4 | |
14 | .LP | |
15 | .ta 4.0i | |
16 | .. | |
17 | .bd S B 3 | |
18 | .RP | |
19 | .TL | |
20 | Ex Reference Manual | |
21 | .br | |
22 | Version 2.0 \- April, 1979 | |
23 | .AU | |
24 | William Joy* | |
25 | .AI | |
26 | Computer Science Division | |
27 | Department of Electrical Engineering and Computer Science | |
28 | University of California, Berkeley | |
29 | Berkeley, Ca. 94720 | |
30 | .AB | |
31 | .I Ex | |
32 | a line oriented text editor, which supports both command and display | |
33 | oriented editing. | |
34 | This reference manual describes the command oriented part of | |
35 | .I ex; | |
36 | the display editing features of | |
37 | .I ex | |
38 | are described in | |
39 | .I "An Introduction to Display Editing with Vi." | |
40 | Other documents about the editor include the introduction | |
41 | .I "Edit: A tutorial", | |
42 | the | |
43 | .I "Ex/edit Command Summary", | |
44 | and a | |
45 | .I "Vi Quick Reference" | |
46 | card. | |
47 | .AE | |
48 | .NH 1 | |
49 | Starting ex | |
50 | .PP | |
51 | .FS | |
52 | * The financial support of an \s-2IBM\s0 Graduate Fellowship and the National | |
53 | Science Foundation under grants MCS74-07644-A03 and MCS78-07291 is gratefully | |
54 | acknowledged. | |
55 | .FE | |
56 | Each instance of the editor has a set of options, | |
57 | which can be set to tailor it to your liking. | |
58 | The command | |
59 | .I edit | |
60 | invokes a version of | |
61 | .I ex | |
62 | designed for more casual or beginning | |
63 | users by changing the default settings of some of these options. | |
64 | To simplify the description which follows we | |
65 | assume the default settings of the options. | |
66 | .PP | |
67 | When invoked, | |
68 | .I ex | |
69 | determines the terminal type from the \s-2TERM\s0 variable in the environment. | |
70 | If there is a file | |
71 | .I \&.exrc | |
72 | in your \s-2HOME\s0 directory | |
73 | .I ex | |
74 | reads commands from that file, simulating a | |
75 | .I source | |
76 | command. | |
77 | Options setting commands placed in | |
78 | .I \&.exrc | |
79 | will be executed before each editor session. | |
80 | .PP | |
81 | A command to enter | |
82 | .I ex | |
83 | has the following prototype:\(dg | |
84 | .FS | |
85 | \(dg Brackets `[' `]' surround optional parameters here. | |
86 | .FE | |
87 | .DS | |
88 | \fBex\fR [ \fB\-\fR ] [ \fB\-v\fR ] [ \fB\-t\fR \fItag\fR ] [ \fB\-r\fR ] [ \fB+\fIlineno\fR ] name ... | |
89 | .DE | |
90 | The most common case edits a single file with no options, i.e.: | |
91 | .DS | |
92 | \fBex\fR name | |
93 | .DE | |
94 | The | |
95 | .B \- | |
96 | command line option | |
97 | option suppresses all interactive-user feedback | |
98 | and is useful in processing editor scripts in command files. | |
99 | The | |
100 | .B \-v | |
101 | option is equivalent to using | |
102 | .I vi | |
103 | rather than | |
104 | .I ex. | |
105 | The | |
106 | .B \-t | |
107 | option is equivalent to an initial | |
108 | .I tag | |
109 | command, editing the file containing the | |
110 | .I tag | |
111 | and positioning the editor at its definition. | |
112 | The | |
113 | .B \-r | |
114 | option is used in recovering after an editor or system crash, | |
115 | retrieving the last saved version of the named file or, | |
116 | if no file is specified, | |
117 | typing a list of saved files. | |
118 | .I Name | |
119 | arguments indicate files to be edited. | |
120 | An argument of the form | |
121 | \fB+\fIlineno\fR | |
122 | indicates that the editor should begin at the specified line in the first | |
123 | file rather than at the last line. | |
124 | .NH 1 | |
125 | File manipulation | |
126 | .NH 2 | |
127 | Current file | |
128 | .PP | |
129 | .I Ex | |
130 | is normally editing the contents of a single file, | |
131 | whose name is recorded in the | |
132 | .I current | |
133 | file name. | |
134 | .I Ex | |
135 | performs all editing actions in a buffer | |
136 | (actually a temporary file) | |
137 | into which the text of the file is initially read. | |
138 | Changes made to the buffer have no effect on the file being | |
139 | edited unless and until the buffer contents are written out to the | |
140 | file with a | |
141 | .I write | |
142 | command. | |
143 | After the buffer contents are written, | |
144 | the previous contents of the written file are no longer accessible. | |
145 | When a file is edited, | |
146 | its name becomes the current file name, | |
147 | and its contents are read into the buffer. | |
148 | .PP | |
149 | The current file is almost always considered to be | |
150 | .I edited. | |
151 | This means that the contents of the buffer are logically | |
152 | connected with the current file name, | |
153 | so that writing the current buffer contents onto that file, | |
154 | even if it exists, | |
155 | is a reasonable action. | |
156 | If the current file is not | |
157 | .I edited | |
158 | then | |
159 | .I ex | |
160 | will not normally write on it if it already exists.* | |
161 | .FS | |
162 | * The | |
163 | .I file | |
164 | command will say ``[Not edited]'' if the current file is not considered | |
165 | edited. | |
166 | .FE | |
167 | .NH 2 | |
168 | Alternate file | |
169 | .PP | |
170 | Each time a new value is given to the current file name, | |
171 | the previous current file name is saved as the | |
172 | .I alternate | |
173 | file name. | |
174 | Similarly if a file is mentioned but does not become the current file, | |
175 | it is saved as the alternate file name. | |
176 | .NH 2 | |
177 | Filename expansion | |
178 | .PP | |
179 | Filenames within the editor may be specified using the normal | |
180 | shell expansion conventions. | |
181 | In addition, | |
182 | the character `%' in filenames is replaced by the | |
183 | .I current | |
184 | file name and the character | |
185 | `#' by the | |
186 | .I alternate | |
187 | file name.\(dg | |
188 | .FS | |
189 | \(dg This makes it easy to deal alternately with | |
190 | two files and eliminates the need for retyping the | |
191 | name supplied on an | |
192 | .I edit | |
193 | command after a | |
194 | .I "No write since last change" | |
195 | diagnostic is received. | |
196 | .FE | |
197 | .NH 2 | |
198 | Multiple files and named buffers | |
199 | .PP | |
200 | If more than one file is given on the command line, | |
201 | then the first file is edited as described above. | |
202 | The remaining arguments are placed with the first file in the | |
203 | .I "argument list." | |
204 | The current argument list may be displayed with the | |
205 | .I args | |
206 | command. | |
207 | The next file in the argument list may be edited with the | |
208 | .I next | |
209 | command. | |
210 | The argument list may also be respecified by specifying | |
211 | a list of names to the | |
212 | .I next | |
213 | command. | |
214 | These names are expanded, | |
215 | the resulting list of names becomes the new argument list, | |
216 | and | |
217 | .I ex | |
218 | edits the first file on the list. | |
219 | .PP | |
220 | For saving blocks of text while editing, and especially when editing | |
221 | more than one file, | |
222 | .I ex | |
223 | has a group of named buffers. | |
224 | These are similar to the normal buffer, except that only a limited number | |
225 | of operations are available on them. | |
226 | The buffers have names | |
227 | .I a | |
228 | through | |
229 | .I z.\(dd | |
230 | .FS | |
231 | \(dd It is also possible to refer to | |
232 | .I A | |
233 | through | |
234 | .I Z; | |
235 | the upper case buffers are the same as the lower but commands | |
236 | append to named buffers rather than replacing | |
237 | if upper case names are used. | |
238 | .FE | |
239 | .NH 1 | |
240 | Exceptional Conditions | |
241 | .NH 2 | |
242 | Errors and interrupts | |
243 | .PP | |
244 | When errors occur | |
245 | .I ex | |
246 | (optionally) rings the terminal bell and, in any case, prints an error | |
247 | diagnostic. If the primary input is from a file, editor processing | |
248 | will terminate. If an interrupt signal is received, | |
249 | .I ex | |
250 | prints ``Interrupt'' and returns to its command level. If the primary | |
251 | input is a file, then | |
252 | .I ex | |
253 | will exit when this occurs. | |
254 | .NH 2 | |
255 | Recovering from hangups and crashes | |
256 | .PP | |
257 | If a hangup signal is received and the buffer has been modified since | |
258 | it was last written out, or if the system crashes, either the editor | |
259 | (in the first case) or the system (after it reboots in the second) will | |
260 | attempt to preserve the buffer. The next time you log in you should be | |
261 | able to recover the work you were doing, losing at most a few lines of | |
262 | changes from the last point before the hangup or editor crash. To | |
263 | recover a file you can use the | |
264 | .B \-r | |
265 | option. If you were editing the file | |
266 | .I resume, | |
267 | then you should change | |
268 | to the directory where you were when the crash occurred, giving the command | |
269 | .DS | |
270 | \fBex \-r\fI resume\fR | |
271 | .DE | |
272 | After checking that the retrieved file is indeed ok, you can | |
273 | .I write | |
274 | it over the previous contents of that file. | |
275 | .PP | |
276 | You will normally get mail from the system telling you when a file has | |
277 | been saved after a crash. The command | |
278 | .DS | |
279 | \fBex\fR \-\fBr\fR | |
280 | .DE | |
281 | will print a list of the files which have been saved for you. | |
282 | .NH 1 | |
283 | Editing modes | |
284 | .PP | |
285 | .I Ex | |
286 | has five distinct modes. The primary mode is | |
287 | .I command | |
288 | mode. Commands are entered in command mode when a `:' prompt is | |
289 | present, and are executed each time a complete line is sent. In | |
290 | .I "text input" | |
291 | mode | |
292 | .I ex | |
293 | gathers input lines and places them in the file. The | |
294 | .I append, | |
295 | .I insert, | |
296 | and | |
297 | .I change | |
298 | commands use text input mode. | |
299 | No prompt is printed when you are in text input mode. | |
300 | This mode is left by typing a `.' alone at the beginning of a line, and | |
301 | .I command | |
302 | mode resumes. | |
303 | .PP | |
304 | The last three modes are | |
305 | .I open | |
306 | and | |
307 | .I visual | |
308 | modes, entered by the commands of the same name, and, within open and | |
309 | visual modes | |
310 | .I "text insertion" | |
311 | mode. | |
312 | .I Open | |
313 | and | |
314 | .I visual | |
315 | modes allow local editing operations to be performed on the text in the | |
316 | file. The | |
317 | .I open | |
318 | command displays one line at a time on any terminal while | |
319 | .I visual | |
320 | works on \s-2CRT\s0 terminals with random positioning cursors, using the | |
321 | screen as a (single) window for file editing changes. | |
322 | These modes are described (only) in | |
323 | .I "An Introduction to Display Editing with Vi." | |
324 | .NH | |
325 | Command structure | |
326 | .PP | |
327 | Most command names are English words, | |
328 | and initial prefixes of the words are acceptable abbreviations. | |
329 | The ambiguity of abbreviations is resolved in favor of the more commonly | |
330 | used commands.* | |
331 | .FS | |
332 | * As an example, the command | |
333 | .I substitute | |
334 | can be abbreviated `s' | |
335 | while the shortest available abbreviation for the | |
336 | .I set | |
337 | command is `se'. | |
338 | .FE | |
339 | .NH 2 | |
340 | Command parameters | |
341 | .PP | |
342 | Most commands accept prefix addresses specifying the lines in the file | |
343 | upon which they are to have effect. | |
344 | The forms of these addresses will be discussed below. | |
345 | A number of commands also may take a trailing | |
346 | .I count | |
347 | specifying the number of lines to be involved in the command.\(dg | |
348 | .FS | |
349 | \(dg Counts are rounded down if necessary. | |
350 | .FE | |
351 | Thus the command ``10p'' will print the tenth line in the buffer while | |
352 | ``delete 5'' will delete five lines from the buffer, | |
353 | starting with the current line. | |
354 | .PP | |
355 | Some commands take other information or parameters, | |
356 | this information always being given after the command name.\(dd | |
357 | .FS | |
358 | \(dd Examples would be option names in a | |
359 | .I set | |
360 | command i.e. ``set number'', | |
361 | a file name in an | |
362 | .I edit | |
363 | command, | |
364 | a regular expression in a | |
365 | .I substitute | |
366 | command, | |
367 | or a target address for a | |
368 | .I copy | |
369 | command, i.e. ``1,5 copy 25''. | |
370 | .FE | |
371 | .NH 2 | |
372 | Command variants | |
373 | .PP | |
374 | A number of commands have two distinct variants. | |
375 | The variant form of the command is invoked by placing an | |
376 | `!' immediately after the command name. | |
377 | Some of the default variants may be controlled by options; | |
378 | in this case, the `!' serves to toggle the default. | |
379 | .NH 2 | |
380 | Flags after commands | |
381 | .PP | |
382 | The characters `#', `p' and `l' may be placed after many commands.* | |
383 | .FS | |
384 | * | |
385 | A `p' or `l' must be preceded by a blank or tab | |
386 | except in the single special case `dp'. | |
387 | .FE | |
388 | In this case, the command abbreviated by these characters | |
389 | is executed after the command completes. | |
390 | Since | |
391 | .I ex | |
392 | normally prints the new current line after each change, `p' is rarely necessary. | |
393 | Any number of `+' or `\-' characters may also be given with these flags. | |
394 | If they appear, the specified offset is applied to the current line | |
395 | value before the printing command is executed. | |
396 | .NH 2 | |
397 | Multiple commands per line | |
398 | .PP | |
399 | More than one command may be placed on a line by separating each pair | |
400 | of commands by a `|' character. | |
401 | However the | |
402 | .I global | |
403 | commands, | |
404 | and the shell escape `!' | |
405 | must be the last command on a line, as they are not terminated by a `|'. | |
406 | .NH 2 | |
407 | Reporting large changes | |
408 | .PP | |
409 | Most commands which change the contents of the editor buffer give | |
410 | feedback if the scope of the change exceeds a threshold given by the | |
411 | .I report | |
412 | option. | |
413 | This feedback helps to detect undesirably large changes so that they may | |
414 | be quickly and easily reversed with an | |
415 | .I undo. | |
416 | After commands with more global effect such as | |
417 | .I global | |
418 | or | |
419 | .I visual, | |
420 | you will be informed if the net change in the number of lines | |
421 | in the buffer during this command exceeds this threshold. | |
422 | .NH 1 | |
423 | Command addressing | |
424 | .NH 2 | |
425 | Addressing primitives | |
426 | .IP \fB.\fR 20 | |
427 | The current line. | |
428 | Most commands leave the current line as the last line which they affect. | |
429 | The default address for most commands is the current line, | |
430 | thus `\fB.\fR' is rarely used alone as an address. | |
431 | .IP \fIn\fR 20 | |
432 | The \fIn\fRth line in the editor's buffer, lines being numbered | |
433 | sequentially from 1. | |
434 | .IP \fB$\fR 20 | |
435 | The last line in the buffer. | |
436 | .IP \fI+n\fR\ \fI\-n\fR 20 | |
437 | An offset relative to the current buffer line.\(dg | |
438 | .FS | |
439 | \(dg | |
440 | The forms `.+2' `++;2' and `++' are all equivalent; | |
441 | if the current line is line 100 they all address line 102. | |
442 | .FE | |
443 | .IP \fB/\fIpat\fR\fB/\fR\ \fB?\fIpat\fR\fB?\fR 20 | |
444 | Scan forward and backward respectively for a line containing \fIpat\fR, a | |
445 | regular expression (as defined below). The scans normally wrap around the end | |
446 | of the buffer. | |
447 | If all that is desired is to print the next line containing \fIpat\fR, then | |
448 | the trailing \fB/\fR or \fB?\fR may be omitted. | |
449 | If \fIpat\fR is omitted or explicitly empty, then the last | |
450 | regular expression specified is located.\(dd | |
451 | .FS | |
452 | \(dd The forms \fB\e/\fR and \fB\e?\fR scan | |
453 | using the last regular expression used in a scan; after a substitute | |
454 | \fB//\fR and \fB??\fR would scan using the substitute's regular expression. | |
455 | .FE | |
456 | .IP \fB\(aa\(aa\fR\ \fB\(aa\fIx\fR 20 | |
457 | Before each non-relative motion of the current line `\fB.\fR', | |
458 | the previous current line is marked with a tag, subsequently referred to as | |
459 | `\(aa\(aa'. | |
460 | This makes it easy to refer or return to this previous context. | |
461 | Marks may also be established by the | |
462 | .I mark | |
463 | command, using single lower case letters | |
464 | .I x | |
465 | and the marked lines referred to as | |
466 | `\(aa\fIx\fR'. | |
467 | .NH 2 | |
468 | Combining addressing primitives | |
469 | .PP | |
470 | Addresses to commands consist of a series of addressing primitives, | |
471 | separated by `,' or `;'. | |
472 | Such address lists are evaluated left-to-right. | |
473 | When addresses are separated by `;' the current line `\fB.\fR' | |
474 | is set to the value of the previous addressing expression | |
475 | before the next address is interpreted. | |
476 | If more addresses are given than the command requires, | |
477 | then all but the last one or two are ignored. | |
478 | If the command takes two addresses, the first addressed line must | |
479 | precede the second in the buffer.\(dg | |
480 | .FS | |
481 | \(dg Null address specifications are permitted in a list of addresses, | |
482 | the default in this case is the current line `.'; | |
483 | thus `,100' is equivalent to `\fB.\fR,100'. | |
484 | It is an error to give a prefix address to a command which expects none. | |
485 | .FE | |
486 | .NH 1 | |
487 | Command descriptions | |
488 | .PP | |
489 | The following form is a prototype for all | |
490 | .I ex | |
491 | commands: | |
492 | .DS | |
493 | \fIaddress\fR \fBcommand\fR \fI! parameters count flags\fR | |
494 | .DE | |
495 | All parts are optional; the degenerate case is the empty command which prints | |
496 | the next line in the file. | |
497 | .PP | |
498 | In the following command descriptions, the | |
499 | default addresses are shown in parentheses, | |
500 | which are | |
501 | .I not, | |
502 | however, | |
503 | part of the command. | |
504 | .LC | |
505 | ( \fB.\fR ) \fBappend\fR abbr: \fBa\fR | |
506 | .br | |
507 | \fItext\fR | |
508 | .br | |
509 | \&\fB.\fR | |
510 | .ZP | |
511 | Reads the input text and places it after the specified line. | |
512 | After the command, `\fB.\fR' | |
513 | addresses the last line input or the | |
514 | specified line if no lines were input. | |
515 | If address `0' is given, | |
516 | text is placed at the beginning of the buffer. | |
517 | .LC | |
518 | \fBa!\fR | |
519 | .br | |
520 | \fItext\fR | |
521 | .br | |
522 | \&\fB.\fR | |
523 | .ZP | |
524 | The variant flag to | |
525 | .I append | |
526 | toggles the setting for the | |
527 | .I autoindent | |
528 | option during the input of | |
529 | .I text. | |
530 | .LC | |
531 | \fBargs\fR | |
532 | .ZP | |
533 | The members of the argument list are printed, with the current argument | |
534 | delimited by `[' and `]'. | |
535 | ...PP | |
536 | ..\fBcd\fR \fIdirectory\fR | |
537 | ...ZP | |
538 | ..The | |
539 | ...I cd | |
540 | ..command is a synonym for | |
541 | ...I chdir. | |
542 | .LC | |
543 | ( \fB.\fR , \fB.\fR ) \fBchange\fR \fIcount\fR abbr: \fBc\fR | |
544 | .br | |
545 | \fItext\fR | |
546 | .br | |
547 | \&\fB.\fR | |
548 | .ZP | |
549 | Replaces the specified lines with the input \fItext\fR. | |
550 | The current line becomes the last line input; | |
551 | if no lines were input it is left as for a | |
552 | \fIdelete\fR. | |
553 | .LC | |
554 | \fBc!\fR | |
555 | .br | |
556 | \fItext\fR | |
557 | .br | |
558 | \&\fB.\fR | |
559 | .ZP | |
560 | The variant toggles | |
561 | .I autoindent | |
562 | during the | |
563 | .I change. | |
564 | ...LC | |
565 | ..\fBchdir\fR \fIdirectory\fR | |
566 | ...ZP | |
567 | ..The specified \fIdirectory\fR becomes the current directory. | |
568 | ..If no directory is specified, the current value of the | |
569 | ...I home | |
570 | ..option is used as the target directory. | |
571 | ..After a | |
572 | ...I chdir | |
573 | ..the current file is not considered to have been | |
574 | ..edited so that write restrictions on pre-existing files apply. | |
575 | .LC | |
576 | ( \fB.\fR , \fB.\fR )\|\fBcopy\fR \fIaddr\fR \fIflags\fR abbr: \fBco\fR | |
577 | .ZP | |
578 | A | |
579 | .I copy | |
580 | of the specified lines is placed after | |
581 | .I addr, | |
582 | which may be `0'. | |
583 | The current line | |
584 | `\fB.\fR' | |
585 | addresses the last line of the copy. | |
586 | The command | |
587 | .I t | |
588 | is a synonym for | |
589 | .I copy. | |
590 | .LC | |
591 | ( \fB.\fR , \fB.\fR )\|\fBdelete\fR \fIbuffer\fR \fIcount\fR \fIflags\fR abbr: \fBd\fR | |
592 | .ZP | |
593 | Removes the specified lines from the buffer. | |
594 | The line after the last line deleted becomes the current line; | |
595 | if the lines deleted were originally at the end, | |
596 | the new last line becomes the current line. | |
597 | If a named | |
598 | .I buffer | |
599 | is specified by giving a letter, | |
600 | then the specified lines are saved in that buffer, | |
601 | or appended to it if an upper case letter is used. | |
602 | .LC | |
603 | \fBedit\fR \fIfile\fR abbr: \fBe\fR | |
604 | .br | |
605 | \fBex\fR \fIfile\fR | |
606 | .ZP | |
607 | Used to begin an editing session on a new file. | |
608 | The editor | |
609 | first checks to see if the buffer has been modified since the last | |
610 | .I write | |
611 | command was issued. | |
612 | If it has been, | |
613 | a warning is issued and the | |
614 | command is aborted. | |
615 | The | |
616 | command otherwise deletes the entire contents of the editor buffer, | |
617 | makes the named file the current file and prints the new filename. | |
618 | After insuring that this file is sensible\(dg | |
619 | .FS | |
620 | \(dg I.e., that it is not a binary file such as a directory, | |
621 | a block or character special file other than | |
622 | .I /dev/tty, | |
623 | a terminal, | |
624 | or a binary or executable file | |
625 | (as indicated by the first word). | |
626 | .FE | |
627 | the editor reads the file into its buffer. | |
628 | .IP | |
629 | If the read of the file completes without error, | |
630 | the number of lines and characters read is typed. | |
631 | If there were any non-\s-2ASCII\s0 characters | |
632 | in the file they are stripped of their non-\s-2ASCII\s0 | |
633 | high bits, | |
634 | and any null characters in the file are discarded. | |
635 | If none of these errors occurred, the file is considered | |
636 | .I edited. | |
637 | If the last line of the input file is missing the trailing | |
638 | newline character, it will be supplied and a complaint will be issued. | |
639 | This command leaves the current line `\fB.\fR' at the last line read.\(dd | |
640 | .FS | |
641 | \(dd If executed from within | |
642 | .I open | |
643 | or | |
644 | .I visual, | |
645 | the current line is initially the first line of the file. | |
646 | .FE | |
647 | .LC | |
648 | \fBe!\fR \fIfile\fR | |
649 | .ZP | |
650 | The variant form suppresses the complaint about modifications having | |
651 | been made and not written from the editor buffer, thus | |
652 | discarding all changes which have been made before editing the new file. | |
653 | .LC | |
654 | \fBe\fR \fB+\fIn\fR \fIfile\fR | |
655 | .ZP | |
656 | Causes the editor to begin at line | |
657 | .I n | |
658 | rather than at the last line. | |
659 | .LC | |
660 | \fBfile\fR abbr: \fBf\fR | |
661 | .ZP | |
662 | Prints the current file name, | |
663 | whether it has been `[Modified]' since the last | |
664 | .I write | |
665 | command, | |
666 | the current line, | |
667 | and the number of lines in the buffer.* | |
668 | .FS | |
669 | * In the rare case that the current file is `[Not edited]' this is | |
670 | noted also; in this case you have to use the form \fBw!\fR to write to | |
671 | the file, since the editor is not sure that a \fBwrite\fR will not | |
672 | destroy a file unrelated to the current contents of the buffer. | |
673 | .FE | |
674 | .LC | |
675 | \fBfile\fR \fIfile\fR | |
676 | .ZP | |
677 | The current file name is changed to | |
678 | .I file | |
679 | which is considered | |
680 | `[Not edited]'. | |
681 | .LC | |
682 | ( 1 , $ ) \fBglobal\fR /\fIpat\|\fR/ \fIcmds\fR abbr: \fBg\fR | |
683 | .ZP | |
684 | First marks each line among those specified which matches | |
685 | the given regular expression. | |
686 | Then the given command list is executed with `\fB.\fR' initially | |
687 | set to each marked line. | |
688 | .IP | |
689 | The command list consists of the remaining commands on the current | |
690 | input line and may continue to multiple lines by ending all but the | |
691 | last such line with a `\e'. | |
692 | .I Append, | |
693 | .I insert, | |
694 | and | |
695 | .I change | |
696 | commands and associated input are permitted; | |
697 | the `\fB.\fR' terminating input may be omitted if it would be on the | |
698 | last line of the command list. | |
699 | .I Open | |
700 | and | |
701 | .I visual | |
702 | commands are permitted in the command list and take input from the terminal. | |
703 | .IP | |
704 | The | |
705 | .I global | |
706 | command itself may not appear in | |
707 | .I cmds. | |
708 | The | |
709 | .I undo | |
710 | command is also not permitted there, | |
711 | as | |
712 | .I undo | |
713 | instead can be used to reverse the entire | |
714 | .I global | |
715 | command. | |
716 | The options | |
717 | .I autoprint | |
718 | and | |
719 | .I autoindent | |
720 | are inhibited during a | |
721 | .I global, | |
722 | and the value of the | |
723 | .I report | |
724 | option is temporarily infinite, | |
725 | in deference to a \fIreport\fR for the entire global. | |
726 | Finally, the context mark `\'\'' is set to the value of | |
727 | `.' before the global command begins and is not changed during a global | |
728 | command, | |
729 | except perhaps by an | |
730 | .I open | |
731 | or | |
732 | .I visual | |
733 | within the | |
734 | .I global. | |
735 | .LC | |
736 | \fBg!\fR \fB/\fIpat\fB/\fR \fIcmds\fR abbr: \fBv\fR | |
737 | .IP | |
738 | The variant form of \fIglobal\fR runs \fIcmds\fR at each line not matching | |
739 | \fIpat\fR. | |
740 | ...LC | |
741 | ..\fBhelp\fR \fItopic\fR | |
742 | ...ZP | |
743 | ..The | |
744 | ...I help | |
745 | ..command accepts keywords related to the editor and, | |
746 | ..if there is information in its data base about that | |
747 | ...I topic | |
748 | ..supplies the information. | |
749 | ..A list of topics can be had by | |
750 | ...I help\ index. | |
751 | .LC | |
752 | ( \fB.\fR )\|\fBinsert\fR abbr: \fBi\fR | |
753 | .br | |
754 | \fItext\fR | |
755 | .br | |
756 | \&\fB.\fR | |
757 | .ZP | |
758 | Places the given text before the specified line. | |
759 | The current line is left at the last line input; | |
760 | if there were none input it is left at the line before the addressed line. | |
761 | This command differs from | |
762 | .I append | |
763 | only in the placement of text. | |
764 | .KS | |
765 | .LC | |
766 | \fBi!\fR | |
767 | .br | |
768 | \fItext\fR | |
769 | .br | |
770 | \&\fB.\fR | |
771 | .ZP | |
772 | The variant toggles | |
773 | .I autoindent | |
774 | during the | |
775 | .I insert. | |
776 | .KE | |
777 | .LC | |
778 | ( \fB.\fR , \fB.\fR+1 ) \fBjoin\fR \fIcount\fR \fIflags\fR abbr: \fBj\fR | |
779 | .ZP | |
780 | Places the text from a specified range of lines | |
781 | together on one line. | |
782 | White space is adjusted at each junction to provide at least | |
783 | one blank character, two if there was a `\fB.\fR' at the end of the line, | |
784 | or none if the first following character is a `)'. | |
785 | If there is already white space at the end of the line, | |
786 | then the white space at the start of the next line will be discarded. | |
787 | .LC | |
788 | \fBj!\fR | |
789 | .ZP | |
790 | The variant causes a simpler | |
791 | .I join | |
792 | with no white space processing; the characters in the lines are simply | |
793 | concatenated. | |
794 | .LC | |
795 | ( \fB.\fR ) \fBk\fR \fIx\fR | |
796 | .ZP | |
797 | The | |
798 | .I k | |
799 | command is a synonym for | |
800 | .I mark. | |
801 | It does not require a blank or tab before the following letter. | |
802 | .LC | |
803 | ( \fB.\fR , \fB.\fR ) \fBlist\fR \fIcount\fR \fIflags\fR | |
804 | .ZP | |
805 | Prints the specified lines in a more unambiguous way: | |
806 | tabs are printed as `^I' | |
807 | and the end of each line is marked with a trailing `$'. | |
808 | The current line is left at the last line printed. | |
809 | .LC | |
810 | ( \fB.\fR ) \fBmark\fR \fIx\fR | |
811 | .ZP | |
812 | Gives the specified line mark | |
813 | .I x, | |
814 | a single lower case letter. | |
815 | The | |
816 | .I x | |
817 | must be preceded by a blank or a tab. | |
818 | The addressing form `\'x' then addresses this line. | |
819 | The current line is not affected by this command. | |
820 | .LC | |
821 | ( \fB.\fR , \fB.\fR ) \fBmove\fR \fIaddr\fR abbr: \fBm\fR | |
822 | .ZP | |
823 | The | |
824 | .I move | |
825 | command repositions the specified lines to be after | |
826 | .I addr . | |
827 | The first of the moved lines becomes the current line. | |
828 | .LC | |
829 | \fBnext\fR abbr: \fBn\fR | |
830 | .ZP | |
831 | The next file from the command line argument list is edited. | |
832 | .LC | |
833 | \fBn!\fR | |
834 | .ZP | |
835 | The variant suppresses warnings about the modifications to the buffer not | |
836 | having been written out, discarding (irretrievably) any changes which may | |
837 | have been made. | |
838 | .LC | |
839 | \fBn\fR \fIfilelist\fR | |
840 | .ZP | |
841 | The specified | |
842 | .I filelist | |
843 | is expanded and the resulting list replaces the | |
844 | current argument list; | |
845 | the first file in the new list is then edited. | |
846 | .LC | |
847 | ( \fB.\fR , \fB.\fR ) \fBnumber\fR \fIcount\fR \fIflags\fR abbr: \fB#\fRf or \fBnu\fR | |
848 | .ZP | |
849 | Prints each specified line preceded by its buffer line | |
850 | number. | |
851 | The current line is left at the last line printed. | |
852 | .KS | |
853 | .LC | |
854 | ( \fB.\fR ) \fBopen\fR \fIflags\fR abbr: \fBo\fR | |
855 | .br | |
856 | ( \fB.\fR ) \fBopen\fR /\fIpat\|\fR/ \fIflags\fR | |
857 | .ZP | |
858 | Enters intraline editing \fIopen\fR mode at each addressed line. | |
859 | If | |
860 | .I pat | |
861 | is given, | |
862 | then the cursor will be placed initially at the beginning of the | |
863 | string matched by the pattern. | |
864 | See | |
865 | .I "An Introduction to Display Editing with Vi" | |
866 | for more details. | |
867 | .KE | |
868 | .LC | |
869 | \fBpreserve\fR | |
870 | .ZP | |
871 | The current editor buffer is saved as though the system had just crashed. | |
872 | This command is for use only in emergencies when a | |
873 | .I write | |
874 | command has resulted in an error and you don't know how to save your work. | |
875 | After a | |
876 | .I preserve | |
877 | you should seek help. | |
878 | .LC | |
879 | ( \fB.\fR , \fB.\fR )\|\fBprint\fR \fIcount\fR abbr: \fBp\fR | |
880 | .ZP | |
881 | Prints the specified lines | |
882 | with non-printing characters printed as control characters `^\fIx\fR\|'; | |
883 | delete (octal 177) is represented as `^?'. | |
884 | The current line is left at the last line printed. | |
885 | .LC | |
886 | ( \fB.\fR )\|\fBput\fR \fIbuffer\fR abbr: \fBpu\fR | |
887 | .ZP | |
888 | Puts back | |
889 | previously | |
890 | .I deleted | |
891 | or | |
892 | .I yanked | |
893 | lines. | |
894 | Normally used with | |
895 | .I delete | |
896 | to effect movement of lines, | |
897 | or with | |
898 | .I yank | |
899 | to effect duplication of lines. | |
900 | If no | |
901 | .I buffer | |
902 | is specified, then the last | |
903 | .I deleted | |
904 | or | |
905 | .I yanked | |
906 | text is restored.* | |
907 | .FS | |
908 | * But no modifying commands may intervene between the | |
909 | .I delete | |
910 | or | |
911 | .I yank | |
912 | and the | |
913 | .I put, | |
914 | nor may lines be moved between files without using a named buffer. | |
915 | .FE | |
916 | By using a named buffer, text may be restored that was saved there at any | |
917 | previous time. | |
918 | .LC | |
919 | \fBquit\fR abbr: \fBq\fR | |
920 | .ZP | |
921 | Causes | |
922 | .I ex | |
923 | to terminate. | |
924 | No automatic write of the editor buffer to a file is performed. | |
925 | However, | |
926 | .I ex | |
927 | issues a warning message if the file has changed | |
928 | since the last | |
929 | .I write | |
930 | command was issued, and does not | |
931 | .I quit.\(dg | |
932 | .FS | |
933 | \(dg \fIEx\fR | |
934 | will also issue a diagnostic if there are more files in the argument | |
935 | list. | |
936 | .FE | |
937 | Normally, you will wish to save your changes, and you | |
938 | should give a \fIwrite\fR command; | |
939 | if you wish to discard them, use the \fBq!\fR command variant. | |
940 | .LC | |
941 | \fBq!\fR | |
942 | .ZP | |
943 | Quits from the editor, discarding changes to the buffer without complaint.\(dg | |
944 | .LC | |
945 | ( \fB.\fR ) \fBread\fR \fIfile\fR abbr: \fBr\fR | |
946 | .ZP | |
947 | Places a copy of the text of the given file in the | |
948 | editing buffer after the specified line. | |
949 | If no | |
950 | .I file | |
951 | is given the current file name is used. | |
952 | The current file name is not changed unless there is none in which | |
953 | case | |
954 | .I file | |
955 | becomes the current name. | |
956 | The sensibility restrictions for the | |
957 | .I edit | |
958 | command apply here also. | |
959 | If the file buffer is empty and there is no current name then | |
960 | .I ex | |
961 | treats this as an | |
962 | .I edit | |
963 | command. | |
964 | .IP | |
965 | Address `0' is legal for this command and causes the file to be read at | |
966 | the beginning of the buffer. | |
967 | Statistics are given as for the | |
968 | .I edit | |
969 | command when the | |
970 | .I read | |
971 | successfully terminates. | |
972 | After a | |
973 | .I read | |
974 | the current line is the last line read.\(dd | |
975 | .FS | |
976 | \(dd Within | |
977 | .I open | |
978 | and | |
979 | .I visual | |
980 | the current line is set to the first line read rather than the last. | |
981 | .FE | |
982 | .LC | |
983 | ( \fB.\fR ) \fBread\fR \fB!\fR\fIcommand\fR | |
984 | .ZP | |
985 | Reads the output of the command | |
986 | .I command | |
987 | into the buffer after the specified line. | |
988 | This is not a variant form of the command, rather a read | |
989 | specifying a | |
990 | .I command | |
991 | rather than a | |
992 | .I filename; | |
993 | a blank or tab before the \fB!\fR is mandatory. | |
994 | .LC | |
995 | \fBrecover \fIfile\fR | |
996 | .ZP | |
997 | Recovers | |
998 | .I file | |
999 | from the system save area. | |
1000 | Used after a accidental hangup of the phone** | |
1001 | .FS | |
1002 | ** The system saves a copy of the file you were editing only if you | |
1003 | have made changes to the file. | |
1004 | .FE | |
1005 | or a system crash** or | |
1006 | .I preserve | |
1007 | command. | |
1008 | Except when you use | |
1009 | .I preserve | |
1010 | you will be notified by mail when a file is saved. | |
1011 | .LC | |
1012 | \fBrewind\fR abbr: \fBrew\fR | |
1013 | .ZP | |
1014 | The argument list is rewound, and the first file in the list is edited. | |
1015 | .LC | |
1016 | \fBrew!\fR | |
1017 | .ZP | |
1018 | Rewinds the argument list discarding any changes made to the current buffer. | |
1019 | .LC | |
1020 | \fBset\fR \fIparameter\fR | |
1021 | .ZP | |
1022 | With no arguments, prints those options whose values have been | |
1023 | changed from their defaults; | |
1024 | with parameter | |
1025 | .I all | |
1026 | it prints all of the option values. | |
1027 | .IP | |
1028 | Giving an option name followed by a `?' | |
1029 | causes the current value of that option to be printed. | |
1030 | The `?' is unnecessary unless the option is Boolean valued. | |
1031 | Boolean options are given values either by the form | |
1032 | `set \fIoption\fR' to turn them on or | |
1033 | `set no\fIoption\fR' to turn them off; | |
1034 | string and numeric options are assigned via the form | |
1035 | `set \fIoption\fR=value'. | |
1036 | .IP | |
1037 | More than one parameter may be given to | |
1038 | .I set \|; | |
1039 | they are interpreted left-to-right. | |
1040 | .LC | |
1041 | \fBshell\fR abbr: \fBsh\fR | |
1042 | .IP | |
1043 | A new shell is created. | |
1044 | When it terminates, editing resumes. | |
1045 | .LC | |
1046 | \fBsource\fR \fIfile\fR abbr: \fBso\fR | |
1047 | .IP | |
1048 | Reads and executes commands from the specified file. | |
1049 | .I Source | |
1050 | commands may be nested. | |
1051 | .LC | |
1052 | ( \fB.\fR , \fB.\fR ) \fBsubstitute\fR /\fIpat\fR\|/\fIrepl\fR\|/ \fIoptions\fR \fIcount\fR \fIflags\fR addr: \fBs\fR | |
1053 | .IP | |
1054 | On each specified line, the first instance of pattern | |
1055 | .I pat | |
1056 | is replaced by replacement pattern | |
1057 | .I repl. | |
1058 | If the | |
1059 | .I global | |
1060 | indicator option character `g' | |
1061 | appears, then all instances are substituted; | |
1062 | if the | |
1063 | .I confirm | |
1064 | indication character `c' appears, | |
1065 | then before each substitution the line to be substituted | |
1066 | is typed with the string to be substituted marked | |
1067 | with `\(ua' characters. | |
1068 | By typing an `y' one can cause the substitution to be performed, | |
1069 | any other input causes no change to take place. | |
1070 | After a | |
1071 | .I substitute | |
1072 | the current line is the last line substituted. | |
1073 | .IP | |
1074 | Lines may be split by substituting | |
1075 | new-line characters into them. | |
1076 | The newline in | |
1077 | .I repl | |
1078 | must be escaped by preceding it with a `\e'.\(dg | |
1079 | .FS | |
1080 | \(dg If the | |
1081 | .I substitute | |
1082 | is within a | |
1083 | .I global, | |
1084 | then two escaping `\e' characters will be needed.) | |
1085 | .FE | |
1086 | Other metacharacters available in | |
1087 | .I pat | |
1088 | and | |
1089 | .I repl | |
1090 | are described below. | |
1091 | .LC | |
1092 | ( \fB.\fR , \fB.\fR ) \fBt\fR \fIaddr\fR \fIflags\fR | |
1093 | .ZP | |
1094 | The | |
1095 | .I t | |
1096 | command is a synonym for | |
1097 | .I copy . | |
1098 | .LC | |
1099 | \fBta\fR \fItag\fR | |
1100 | .ZP | |
1101 | The focus of editing switches to the location of | |
1102 | .I tag, | |
1103 | switching to a different line in the current file where it is defined, | |
1104 | or if necessary to another file.\(dd | |
1105 | .FS | |
1106 | \(dd If you have modified the current file before giving a | |
1107 | .I tag | |
1108 | command, you must write it out; giving another | |
1109 | .I tag | |
1110 | command, specifying no | |
1111 | .I tag | |
1112 | will reuse the previous tag. | |
1113 | .FE | |
1114 | .IP | |
1115 | The tags file is normally created by a program such as | |
1116 | .I ctags, | |
1117 | and consists of a number of lines with three fields separated by blanks | |
1118 | or tabs. The first field gives the name of the tag, | |
1119 | the second the name of the file where the tag resides, and the third | |
1120 | gives an addressing form which can be used by the editor to find the tag; | |
1121 | this field is usually a contextual scan using `/\fIpat\fR/' to be immune | |
1122 | to minor changes in the file. | |
1123 | .LC | |
1124 | \fBundo\fR abbr: \fBu\fR | |
1125 | .ZP | |
1126 | Reverses the changes made in the buffer by the last | |
1127 | buffer editing command. | |
1128 | Note that | |
1129 | .I global | |
1130 | commands are considered a single command for the purpose of | |
1131 | .I undo | |
1132 | (as are | |
1133 | .I open | |
1134 | and | |
1135 | .I visual.) | |
1136 | Also, the commands | |
1137 | .I write | |
1138 | and | |
1139 | .I edit | |
1140 | which interact with the | |
1141 | file system cannot be undone. | |
1142 | .I Undo | |
1143 | is its own inverse. | |
1144 | .IP | |
1145 | .I Undo | |
1146 | always marks the previous value of the current line `\fB.\fR' | |
1147 | as `\'\''. | |
1148 | After an | |
1149 | .I undo | |
1150 | the current line is the first line restored | |
1151 | or the line before the first line deleted if no lines were restored. | |
1152 | For commands with more global effect | |
1153 | such as | |
1154 | .I global | |
1155 | and | |
1156 | .I visual | |
1157 | the current line regains it pre-command value after an | |
1158 | .I undo. | |
1159 | .LC | |
1160 | ( 1 , $ ) \fBv\fR /\fIpat\fR\|/ \fIcmds\fR | |
1161 | .ZP | |
1162 | A synonym for the | |
1163 | .I global | |
1164 | command variant \fBg!\fR, running the specified \fIcmds\fR on each | |
1165 | line which does not match \fIpat\fR. | |
1166 | .LC | |
1167 | \fBversion\fR abbr: \fBve\fR | |
1168 | .ZP | |
1169 | Prints the current version number of the editor | |
1170 | as well as the date the binary was created. | |
1171 | .LC | |
1172 | ( \fB.\fR ) \fBvisual\fR \fItype\fR \fIcount\fR \fIflags\fR abbr: \fBvi\fR | |
1173 | .ZP | |
1174 | Enters visual mode at the specified line. | |
1175 | .I Type | |
1176 | is optional and may be `\-' , `\(ua' or `\fB.\fR' | |
1177 | as in the | |
1178 | .I z | |
1179 | command to specify the placement of the specified line on the screen. | |
1180 | By default, if | |
1181 | .I type | |
1182 | is omitted, the specified line is placed as the first on the screen. | |
1183 | A | |
1184 | .I count | |
1185 | specifies an initial window size; the default is the value of the option | |
1186 | .I window. | |
1187 | See the document | |
1188 | .I "An Introduction to Display Editing with Vi" | |
1189 | for more details. | |
1190 | .LC | |
1191 | ( 1 , $ ) \fBwrite\fR \fIfile\fR abbr: \fBw\fR | |
1192 | .ZP | |
1193 | Writes changes made back to \fIfile\fR, printing the number of lines and | |
1194 | characters written. | |
1195 | Normally \fIfile\fR is omitted and the text goes back where it came from. | |
1196 | If a \fIfile\fR is specified, then text will be written to that file.* | |
1197 | .FS | |
1198 | * The editor writes to a file only if it is | |
1199 | the current file and is | |
1200 | .I edited , | |
1201 | if the file does not exist, | |
1202 | or if the file is actually a teletype, | |
1203 | .I /dev/tty, | |
1204 | .I /dev/null. | |
1205 | Otherwise, you must give the variant form \fBw!\fR to force the write. | |
1206 | .FE | |
1207 | If the file does not exist it is created. | |
1208 | The current file name is changed only if there is no current file | |
1209 | name; the current line is never changed. | |
1210 | .IP | |
1211 | If an error occurs while writing the current and | |
1212 | .I edited | |
1213 | file, the editor | |
1214 | considers that there has been ``No write since last change'' | |
1215 | even if the buffer had not previously been modified. | |
1216 | .LC | |
1217 | ( 1 , $ ) \fBwrite>>\fR \fIfile\fR abbr: \fBw>>\fR | |
1218 | .ZP | |
1219 | Writes the buffer contents at the end of | |
1220 | an existing file. | |
1221 | .IP | |
1222 | .LC | |
1223 | \fBw!\fR \fIname\fR | |
1224 | .ZP | |
1225 | Overrides the checking of the normal \fIwrite\fR command, | |
1226 | and will write to any file which the system permits. | |
1227 | .LC | |
1228 | ( 1 , $ ) \fBw\fR \fB!\fR\fIcommand\fR | |
1229 | .ZP | |
1230 | Writes the specified lines into | |
1231 | .I command. | |
1232 | Note the difference between \fBw!\fR which overrides checks and | |
1233 | \fBw\ \ !\fR which writes to a command. | |
1234 | .LC | |
1235 | \fBwq\fR \fIname\fR | |
1236 | .ZP | |
1237 | Like a \fIwrite\fR and then a \fIquit\fR command. | |
1238 | .LC | |
1239 | \fBwq!\fR \fIname\fR | |
1240 | .ZP | |
1241 | The variant overrides checking on the sensibility of the | |
1242 | .I write | |
1243 | command, as \fBw!\fR does. | |
1244 | .LC | |
1245 | ( \fB.\fR , \fB.\fR )\|\fByank\fR \fIbuffer\fR \fIcount\fR abbr: \fBya\fR | |
1246 | .ZP | |
1247 | Places the specified lines in the named | |
1248 | .I buffer, | |
1249 | for later retrieval via | |
1250 | .I put. | |
1251 | If no buffer name is specified, the lines go to a more volatile place; | |
1252 | see the \fIput\fR command description. | |
1253 | .LC | |
1254 | ( \fB.\fR ) \fBz\fR \fItype\fR \fIcount\fR | |
1255 | .ZP | |
1256 | Prints a window of text with the specified line at the top. | |
1257 | If \fItype\fR is `\-' the line is placed at the bottom; a `\fB.\fR' causes | |
1258 | the line to be placed in the center.* | |
1259 | A count gives the number of lines to be displayed rather than | |
1260 | the number specified by the \fIwindow\fR option. | |
1261 | On a \s-2CRT\s0 the screen is cleared before display begins unless a | |
1262 | count which is less than the screen size is given. | |
1263 | The current line is left at the last line printed. | |
1264 | .FS | |
1265 | * Forms `z=' and `z\(ua' also exist; `z=' places the current line in the | |
1266 | center, surrounds it with lines of `\-' characters and leaves the current | |
1267 | line at this line. The form `z\(ua' prints the window before `z\-' | |
1268 | would. The characters `+', `\(ua' and `\-' may be repeated for cumulative | |
1269 | effect. | |
1270 | .FE | |
1271 | .LC | |
1272 | \fB!\fR \fIcommand\fR\fR | |
1273 | .ZP | |
1274 | The remainder of the line after the `!' character is sent to a shell | |
1275 | to be executed. | |
1276 | Within the text of | |
1277 | .I command | |
1278 | the characters | |
1279 | `%' and `#' are expanded as in filenames and the character | |
1280 | `!' is replaced with the text of the previous command. | |
1281 | Thus, in particular, | |
1282 | `!!' repeats the last such shell escape. | |
1283 | If any such expansion is performed, the expanded line will be echoed. | |
1284 | The current line is unchanged by this command. | |
1285 | .IP | |
1286 | If there has been ``[No\ write]'' of the buffer contents since the last | |
1287 | change to the editing buffer, then a diagnostic will be printed | |
1288 | before the command is executed as a warning. | |
1289 | A single `!' is printed when the command completes. | |
1290 | .LC | |
1291 | ( \fIaddr\fR , \fIaddr\fR ) \fB!\fR \fIcommand\fR\fR | |
1292 | .ZP | |
1293 | Takes the specified address range and supplies it as | |
1294 | standard input to | |
1295 | .I command; | |
1296 | the resulting output then replaces the input lines. | |
1297 | .LC | |
1298 | ( $ ) \fB=\fR | |
1299 | .ZP | |
1300 | Prints the line number of the | |
1301 | addressed line. | |
1302 | The current line is unchanged. | |
1303 | .KS | |
1304 | .LC | |
1305 | ( \fB.\fR , \fB.\fR ) \fB>\fR \fIcount\fR \fIflags\fR | |
1306 | .br | |
1307 | ( \fB.\fR , \fB.\fR ) \fB<\fR \fIcount\fR \fIflags\fR | |
1308 | .IP | |
1309 | Perform intelligent shifting on the specified lines; | |
1310 | \fB<\fR shifts left and \fB>\fR shift right. | |
1311 | The quantity of shift is determined by the | |
1312 | .I shiftwidth | |
1313 | option and the repetition of the specification character. | |
1314 | Only white space (blanks and tabs) is shifted; | |
1315 | no non-white characters are discarded in a left-shift. | |
1316 | The current line becomes the last line which changed due to the | |
1317 | shifting. | |
1318 | .KE | |
1319 | .LC | |
1320 | \fB^D\fR | |
1321 | .ZP | |
1322 | An end-of-file from a terminal input scrolls through the file. | |
1323 | The | |
1324 | .I scroll | |
1325 | option specifies the size of the scroll, normally a half screen of text. | |
1326 | .LC | |
1327 | ( \fB.\fR+1 ) | |
1328 | .br | |
1329 | ( \fB.\fR+1 ) | | |
1330 | .ZP | |
1331 | An address alone causes the addressed line to be printed. | |
1332 | A blank line prints the next line in the file. | |
1333 | .LC | |
1334 | ( \fB.\fR , \fB.\fR ) \fB&\fR \fIoptions\fR \fIcount\fR \fIflags\fR | |
1335 | .ZP | |
1336 | Repeats the previous | |
1337 | .I substitute | |
1338 | command. | |
1339 | .LC | |
1340 | ( \fB.\fR , \fB.\fR ) \fB\s+2~\s0\fR \fIoptions\fR \fIcount\fR \fIflags\fR | |
1341 | .ZP | |
1342 | Replaces the previous regular expression with the previous | |
1343 | replacement pattern from a substitution. | |
1344 | .NH 1 | |
1345 | Regular expressions and substitute replacement patterns | |
1346 | .NH 2 | |
1347 | Regular expressions | |
1348 | .PP | |
1349 | A regular expression specifies a set of strings of characters. | |
1350 | A member of this set of strings is said to be | |
1351 | .I matched | |
1352 | by the regular expression. | |
1353 | .I Ex | |
1354 | remembers two previous regular expressions: | |
1355 | the previous regular expression used in a | |
1356 | .I substitute | |
1357 | command | |
1358 | and the previous regular expression used elsewhere | |
1359 | (referred to as the previous \fIscanning\fR regular expression.) | |
1360 | The previous regular expression | |
1361 | can always be referred to by a null \fIre\fR, e.g. `//' or `??'. | |
1362 | .NH 2 | |
1363 | Magic and nomagic | |
1364 | .PP | |
1365 | The regular expressions allowed by | |
1366 | .I ex | |
1367 | are constructed in one of two ways depending on the setting of | |
1368 | the | |
1369 | .I magic | |
1370 | option. | |
1371 | The | |
1372 | .I ex | |
1373 | default setting of | |
1374 | .I magic | |
1375 | gives quick access to a powerful set of regular expression | |
1376 | metacharacters. | |
1377 | The disadvantage of | |
1378 | .I magic | |
1379 | is that the user must remember that these metacharacters are | |
1380 | .I magic | |
1381 | and precede them with the character `\e' | |
1382 | to use them as ``ordinary'' characters. | |
1383 | With | |
1384 | .I nomagic, | |
1385 | the default for | |
1386 | .I edit | |
1387 | and | |
1388 | .I vi, | |
1389 | regular expressions are much simpler, | |
1390 | there being only two metacharacters. | |
1391 | The power of the other metacharacters is still available by preceding | |
1392 | the (now) ordinary character with a `\e'. | |
1393 | Note that `\e' is thus always a metacharacter. | |
1394 | .PP | |
1395 | The remainder of the discussion of regular expressions assumes | |
1396 | that | |
1397 | that the setting of this option is | |
1398 | .I magic.\(dg | |
1399 | .FS | |
1400 | \(dg To discern what is true with | |
1401 | .I nomagic | |
1402 | it suffices to remember that the only | |
1403 | special characters in this case will be `\(ua' at the beginning | |
1404 | of a regular expression, | |
1405 | `$' at the end of a regular expression, | |
1406 | and `\e'. | |
1407 | With | |
1408 | .I nomagic | |
1409 | the characters `\s+2~\s0' and `&' also lose their special meanings | |
1410 | related to the replacement pattern of a substitute. | |
1411 | .FE | |
1412 | .NH 2 | |
1413 | Basic regular expression summary | |
1414 | .PP | |
1415 | The following basic constructs are used to construct | |
1416 | .I magic | |
1417 | mode regular expressions. | |
1418 | .IP \fIchar\fR 15 | |
1419 | An ordinary character matches itself. | |
1420 | The characters `\(ua' at the beginning of a line, | |
1421 | `$' at the end of line, | |
1422 | `*' as any character other than the first, | |
1423 | `.', `\e', `[', and `\s+2~\s0' are not ordinary characters and | |
1424 | must be escaped (preceded) by `\e' to be treated as such. | |
1425 | .IP \fB\(ua\fR | |
1426 | At the beginning of a pattern | |
1427 | forces the match to succeed only at the beginning of a line. | |
1428 | .IP \fB$\fR | |
1429 | At the end of a regular expression forces the match to | |
1430 | succeed only at the end of the line. | |
1431 | .IP \&\fB.\fR | |
1432 | Matches any single character except | |
1433 | the new-line character. | |
1434 | .IP \fB\e<\fR | |
1435 | Forces the match | |
1436 | to occur only at the beginning of a ``variable'' or ``word''; | |
1437 | that is, either at the beginning of a line, or just before | |
1438 | a letter, digit, or underline and after a character not one of | |
1439 | these. | |
1440 | .IP \fB\e>\fR | |
1441 | Similar to `\e<', but matching the end of a ``variable'' | |
1442 | or ``word'', i.e. either the end of the line or before character | |
1443 | which is neither a letter, nor a digit, nor the underline character. | |
1444 | .IP \fB[\fIstring\fR]\fR | |
1445 | Matches any (single) character in the class defined by | |
1446 | .I string. | |
1447 | Most characters in | |
1448 | .I string | |
1449 | define themselves. | |
1450 | A pair of characters separated by `\-' in | |
1451 | .I string | |
1452 | defines the set of characters collating between the specified lower and upper | |
1453 | bounds, thus `[a\-z]' as a regular expression matches | |
1454 | any (single) lower-case letter. | |
1455 | If the first character of | |
1456 | .I string | |
1457 | is an `\(ua' then the construct | |
1458 | matches those characters which it otherwise would not; | |
1459 | thus `[\(uaa\-z]' matches anything but a lower-case letter (and of course a | |
1460 | newline). | |
1461 | To place any of the characters | |
1462 | `\(ua', `[', or `\-' in | |
1463 | .I string | |
1464 | you must escape them with a preceding `\e'. | |
1465 | .NH 2 | |
1466 | Combining regular expression primitives | |
1467 | .PP | |
1468 | The concatenation of two regular expressions matches the leftmost and | |
1469 | then longest string | |
1470 | which can be divided with the first piece matching the first regular | |
1471 | expression and the second piece matching the second. | |
1472 | Any of the (single character matching) regular expressions mentioned | |
1473 | above may be followed by the character `*' to form a regular expression | |
1474 | which matches any number of adjacent occurrences (including 0) of characters | |
1475 | matched by the regular expression it follows. | |
1476 | .PP | |
1477 | The character `\s+2~\s0' may be used in a regular expression, | |
1478 | and matches the text which defined the replacement part | |
1479 | of the last | |
1480 | .I substitute | |
1481 | command. | |
1482 | A regular expression may be enclosed between the sequences | |
1483 | `\e(' and `\e)' with side effects in the | |
1484 | .I substitute | |
1485 | replacement patterns. | |
1486 | .NH 2 | |
1487 | Substitute replacement patterns | |
1488 | .PP | |
1489 | The basic metacharacters for the replacement pattern are | |
1490 | `&' and `~'; these are | |
1491 | given as `\e&' and `\e~' when | |
1492 | .I nomagic | |
1493 | is set. | |
1494 | Each instance of `&' is replaced by the characters | |
1495 | which the regular expression matched. | |
1496 | The metacharacter `~' stands, in the replacement pattern, | |
1497 | for the defining text of the previous replacement pattern. | |
1498 | .PP | |
1499 | Other metasequences possible in the replacement pattern | |
1500 | are always introduced by the escaping character `\e'. | |
1501 | The sequence `\e\fIn\fR' is replaced by the text matched | |
1502 | by the \fIn\fR-th regular subexpression enclosed between | |
1503 | `\e(' and `\e)'.\(dg | |
1504 | .FS | |
1505 | \(dg When nested, parenthesized subexpressions are present, | |
1506 | \fIn\fR is determined by counting occurrences of `\e(' starting from the left. | |
1507 | .FE | |
1508 | The sequences `\eu' and `\el' cause the immediately following character in | |
1509 | the replacement to be converted to upper- or lower-case respectively | |
1510 | if this character is a letter. | |
1511 | The sequences `\eU' and `\eL' turn such conversion on, either until | |
1512 | `\eE' or `\ee' is encountered, or until the end of the replacement pattern. | |
1513 | .NH 1 | |
1514 | Option descriptions | |
1515 | .PP | |
1516 | .LC | |
1517 | \fBautoindent\fR, \fBai\fR default: noai | |
1518 | .ZP | |
1519 | Can be used to ease the preparation of structured program text. | |
1520 | At the beginning of each | |
1521 | .I append , | |
1522 | .I change | |
1523 | or | |
1524 | .I insert | |
1525 | command | |
1526 | or when a new line is | |
1527 | .I opened | |
1528 | or created by an | |
1529 | .I append , | |
1530 | .I change , | |
1531 | .I insert , | |
1532 | or | |
1533 | .I substitute | |
1534 | operation within | |
1535 | .I open | |
1536 | or | |
1537 | .I visual | |
1538 | mode, | |
1539 | .I ex | |
1540 | looks at the line being appended after, | |
1541 | the first line changed | |
1542 | or the line inserted before and calculates the amount of white space | |
1543 | at the start of the line. | |
1544 | It then aligns the cursor at the level of indentation so determined. | |
1545 | .IP | |
1546 | If the user then types lines of text in, | |
1547 | they will continue to be justified at the displayed indenting level. | |
1548 | If more white space is typed at the beginning of a line, | |
1549 | the following line will start aligned with the first non-white character | |
1550 | of the previous line. | |
1551 | To back the cursor up to the preceding tab stop one can hit | |
1552 | \fB^D\fR. | |
1553 | The tab stops going backwards are defined at multiples of the | |
1554 | .I shiftwidth | |
1555 | option. | |
1556 | You | |
1557 | .I cannot | |
1558 | backspace over the indent, | |
1559 | except by sending an end-of-file with a \fB^D\fR. | |
1560 | .IP | |
1561 | Specially processed in this mode is a line with no characters added | |
1562 | to it, which turns into a completely blank line (the white | |
1563 | space provided for the | |
1564 | .I autoindent | |
1565 | is discarded.) | |
1566 | Also specially processed in this mode are lines beginning with | |
1567 | an `\(ua' and immediately followed by a \fB^D\fR. | |
1568 | This causes the input to be repositioned at the beginning of the line, | |
1569 | but retaining the previous indent for the next line. | |
1570 | Similarly, a `0' followed by a \fB^D\fR | |
1571 | repositions at the beginning but without | |
1572 | retaining the previous indent. | |
1573 | .IP | |
1574 | .I Autoindent | |
1575 | doesn't happen in | |
1576 | .I global | |
1577 | commands or when the input is not a terminal. | |
1578 | .LC | |
1579 | \fBautoprint\fR, \fBap\fR default: ap | |
1580 | .ZP | |
1581 | Causes the current line to be printed after each | |
1582 | .I delete , | |
1583 | .I copy , | |
1584 | .I join , | |
1585 | .I move , | |
1586 | .I substitute , | |
1587 | .I t , | |
1588 | .I undo | |
1589 | or | |
1590 | shift command. | |
1591 | This has the same effect as supplying a trailing `p' | |
1592 | to each such command. | |
1593 | .I Autoprint | |
1594 | is suppressed in globals, | |
1595 | and only applies to the last of many commands on a line. | |
1596 | .LC | |
1597 | \fBbeautify\fR, \fBbf\fR default: nobeautify | |
1598 | .ZP | |
1599 | Causes all control characters except tab, newline and form-feed | |
1600 | to be discarded from the input. | |
1601 | A complaint is registered the first time a | |
1602 | backspace character is discarded. | |
1603 | .I Beautify | |
1604 | does not apply to command input. | |
1605 | .LC | |
1606 | \fBdirectory\fR, \fBdir\fR default: dir=/tmp | |
1607 | .ZP | |
1608 | Specifies the directory in which | |
1609 | .I ex | |
1610 | places its buffer file. | |
1611 | If this directory in not | |
1612 | writable, then the editor will exit abruptly when it fails to be | |
1613 | able to create its buffer there. | |
1614 | .LC | |
1615 | \fBerrorbells\fR, \fBeb\fR default: eb | |
1616 | .ZP | |
1617 | Error messages are preceded by a bell.* | |
1618 | .FS | |
1619 | * Bell ringing in | |
1620 | .I open | |
1621 | and | |
1622 | .I visual | |
1623 | on errors is not suppressed by setting | |
1624 | .I noeb. | |
1625 | .FE | |
1626 | If possible the editor always places the error message in a standout mode of the | |
1627 | terminal (such as inverse video) instead of ringing the bell. | |
1628 | .LC | |
1629 | \fBignorecase\fR, \fBic\fR default: noic | |
1630 | .ZP | |
1631 | All upper case characters in the text are mapped to lower case in regular | |
1632 | expression matching. | |
1633 | In addition, all upper case characters in regular expressions are mapped | |
1634 | to lower case except in character class specifications. | |
1635 | .LC | |
1636 | \fBlisp\fR default: nolisp | |
1637 | .ZP | |
1638 | \fIAutoindent\fR indents appropriately for | |
1639 | .I lisp | |
1640 | code, and the \fB( ) { } [[\fR and \fB]]\fR commands in | |
1641 | .I open | |
1642 | and | |
1643 | .I visual | |
1644 | are modified to have meaning for \fIlisp\fR. | |
1645 | .LC | |
1646 | \fBlist\fR default: nolist | |
1647 | .ZP | |
1648 | All printed lines will be displayed (more) unambiguously, | |
1649 | showing tabs and end-of-lines as in the | |
1650 | .I list | |
1651 | command. | |
1652 | .LC | |
1653 | \fBmagic\fR default: magic for \fIex\fR\(dg | |
1654 | .FS | |
1655 | \(dg \fINomagic\fR for \fIedit\fR and \fIvi\fR. | |
1656 | .FE | |
1657 | .ZP | |
1658 | If | |
1659 | .I nomagic | |
1660 | is set, the number of regular expression metacharacters is greatly reduced, | |
1661 | with only `\(ua' and `$' having special effects. | |
1662 | In addition the metacharacters | |
1663 | `~' | |
1664 | and | |
1665 | `&' | |
1666 | of the replacement pattern are treated as normal characters. | |
1667 | All the normal metacharacters may be made | |
1668 | .I magic | |
1669 | when | |
1670 | .I nomagic | |
1671 | is set by preceding them with a `\e'. | |
1672 | .LC | |
1673 | \fBnumber, nu\fR default: nonumber | |
1674 | .ZP | |
1675 | Causes all output lines to be printed with their | |
1676 | line numbers. | |
1677 | In addition each input line will be prompted for by supplying the line number | |
1678 | it will have. | |
1679 | .LC | |
1680 | \fBopen\fR default: open | |
1681 | .ZP | |
1682 | If \fInoopen\fR, the commands | |
1683 | .I open | |
1684 | and | |
1685 | .I visual | |
1686 | are not permitted. | |
1687 | This is set for | |
1688 | .I edit | |
1689 | to prevent confusion resulting from accidental entry to | |
1690 | open or visual mode. | |
1691 | .LC | |
1692 | \fBoptimize, opt\fR default: optimize | |
1693 | .ZP | |
1694 | Throughput of text is expedited by setting the terminal | |
1695 | to not do automatic carriage returns | |
1696 | when printing more than one (logical) line of output. | |
1697 | greatly speeding output on terminals without addressable | |
1698 | cursors when text with leading white space is printed. | |
1699 | .LC | |
1700 | \fBparagraphs,\ para\fR default: para=IPLPPPQPbp | |
1701 | .ZP | |
1702 | Specifies the paragraphs for the \fB{\fR and \fB}\fR operations in | |
1703 | .I open | |
1704 | and | |
1705 | .I visual. | |
1706 | The pairs of characters in the option's value are the names | |
1707 | of the macros which start paragraphs. | |
1708 | .LC | |
1709 | \fBprompt\fR default: prompt | |
1710 | .ZP | |
1711 | Command mode input is prompted for with a `:'. | |
1712 | .LC | |
1713 | \fBreport\fR default: report=5\(dg | |
1714 | .FS | |
1715 | \(dg 2 for \fIedit\fR. | |
1716 | .FE | |
1717 | .ZP | |
1718 | Specifies a threshold for feedback from commands. | |
1719 | Any command which modifies more than the specified number of lines | |
1720 | will provide feedback as to the scope of its changes. | |
1721 | For commands such as | |
1722 | .I global , | |
1723 | .I open , | |
1724 | .I undo , | |
1725 | and | |
1726 | .I visual | |
1727 | which have potentially more far reaching scope, | |
1728 | the net change in the number of lines in the buffer is | |
1729 | presented at the end of the command, subject to this same threshold. | |
1730 | Thus notification is suppressed during a | |
1731 | .I global | |
1732 | command on the individual commands performed. | |
1733 | .LC | |
1734 | \fBscroll\fR default: scroll=12 | |
1735 | .ZP | |
1736 | Determines the number of logical lines scrolled when an end-of-file | |
1737 | is received from a terminal input. | |
1738 | .LC | |
1739 | \fBsections\fR default: sections=SHNH | |
1740 | .ZP | |
1741 | Specifies the section macros for the \fB[[\fR and \fB]]\fR operations | |
1742 | in | |
1743 | .I open | |
1744 | and | |
1745 | .I visual. | |
1746 | The pairs of characters in the options's value are the names | |
1747 | of the macros which start paragraphs. | |
1748 | .LC | |
1749 | \fBshell\fR, \fBsh\fR default: sh=/bin/sh | |
1750 | .ZP | |
1751 | Gives the path name of the shell forked for | |
1752 | the shell escape command `!', and by the | |
1753 | .I shell | |
1754 | command. | |
1755 | .LC | |
1756 | \fBshiftwidth\fR, \fBsw\fR default: sw=8 | |
1757 | .ZP | |
1758 | Gives the width a software tab stop, | |
1759 | used in reverse tabbing with \fB^D\fR when using | |
1760 | .I autoindent | |
1761 | to append text, | |
1762 | and by the shift commands. | |
1763 | .LC | |
1764 | \fBshowmatch, sm\fR default: nosm | |
1765 | .ZP | |
1766 | In | |
1767 | .I open | |
1768 | and | |
1769 | .I visual | |
1770 | mode, when a \fB)\fR or \fB}\fR is typed, move the cursor to the matching | |
1771 | \fB(\fR or \fB{\fR for one second if this matching character is on the | |
1772 | screen. Extremely useful with | |
1773 | .I lisp. | |
1774 | .LC | |
1775 | \fBslowopen, slow\fR terminal dependent | |
1776 | .ZP | |
1777 | Affects the display algorithm used in | |
1778 | .I visual | |
1779 | mode, holding off display updating during input of new text to improve | |
1780 | throughput when the terminal in use is both slow and unintelligent. | |
1781 | See | |
1782 | .I "An Introduction to Display Editing with Vi" | |
1783 | for more details. | |
1784 | .LC | |
1785 | \fBtabstop,\ ts\fR default: ts=8 | |
1786 | .ZP | |
1787 | The editor expands tabs in the input file to be on | |
1788 | .I tabstop | |
1789 | boundaries for the purposes of display. | |
1790 | .LC | |
1791 | \fBterm\fR from environment | |
1792 | .ZP | |
1793 | The terminal type of the output device. | |
1794 | .LC | |
1795 | \fBterse\fR default: noterse | |
1796 | .ZP | |
1797 | Shorter error diagnostics are produced for the experienced user. | |
1798 | .LC | |
1799 | \fBwarn\fR default: warn | |
1800 | .ZP | |
1801 | Warn if there has been `[No write since last change]' before a `!' | |
1802 | command escape. | |
1803 | .LC | |
1804 | \fBwindow\fR default: window=23 | |
1805 | .ZP | |
1806 | The number of lines in a text window for the | |
1807 | .I z | |
1808 | and | |
1809 | .I visual | |
1810 | commands. | |
1811 | .LC | |
1812 | \fBwrapscap\fR, \fBws\fR default: ws | |
1813 | .ZP | |
1814 | Searches using the regular expressions in addressing | |
1815 | will wrap around past the end of the file. | |
1816 | .LC | |
1817 | \fBwrapmargin\fR, \fBwm\fR default: wm=0 | |
1818 | .ZP | |
1819 | Defines a margin for automatic wrapover of text during input in | |
1820 | .I open | |
1821 | and | |
1822 | .I visual | |
1823 | modes. See | |
1824 | .I "An Introduction to Text Editing with Vi" | |
1825 | for details. | |
1826 | .LC | |
1827 | \fBwriteany\fR, \fBwa\fR default: nowa | |
1828 | .IP | |
1829 | Inhibit the checks normally made before | |
1830 | .I write | |
1831 | commands, allowing a write to any file which the system protection | |
1832 | mechanism will allow. | |
1833 | .NH 1 | |
1834 | Limitations | |
1835 | .PP | |
1836 | This editor uses a temporary file as a workspace | |
1837 | and each line in the buffer is represented by an in-core pointer to the | |
1838 | image of that line on the disk. | |
1839 | The editor does | |
1840 | .I not | |
1841 | reclaim space in this temporary file used by lines which are | |
1842 | deleted or changed. | |
1843 | This means that files which are larger than 128K characters | |
1844 | may be difficult to edit, and that | |
1845 | systematic changes on large numbers of lines may | |
1846 | run the editor out of temporary file space. | |
1847 | .PP | |
1848 | If the editor runs out of temporary space you can write the file | |
1849 | and then use an | |
1850 | .I edit | |
1851 | command to read it back in. | |
1852 | This will reclaim the lost space. | |
1853 | A better solution is to split the file into smaller pieces or to use a stream | |
1854 | editor such as | |
1855 | .I sed | |
1856 | on the file. | |
1857 | .PP | |
1858 | Other editor limits that the user is likely to encounter are as follows: | |
1859 | 512 characters per line, | |
1860 | 256 characters per global command list, | |
1861 | 64 characters per file name, | |
1862 | 128 characters in the previous inserted and deleted text in | |
1863 | .I open | |
1864 | or | |
1865 | .I visual, | |
1866 | 100 characters in a shell escape command, | |
1867 | 30 characters in a string valued option, | |
1868 | 30 characters in a tag name, | |
1869 | and | |
1870 | 256K characters in the temporary file. | |
1871 | The limit on the number of lines depends on the amount of core: | |
1872 | each line takes at least 1 word, and to effect | |
1873 | .I undo | |
1874 | occasionally up to 2. |