]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/nvi/docs/USD.doc/vi.ref/vi.ref
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / nvi / docs / USD.doc / vi.ref / vi.ref
1 .\" Copyright (c) 1994
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\" Copyright (c) 1994, 1995, 1996
4 .\"     Keith Bostic.  All rights reserved.
5 .\"
6 .\" This document may not be republished without written permission from
7 .\" Keith Bostic. 
8 .\"
9 .\" See the LICENSE file for redistribution information.
10 .\"
11 .\"     @(#)vi.ref      8.88 (Berkeley) 10/19/96
12 .\"
13 .\" $FreeBSD$
14 .\"
15 .so ref.so
16 .tp
17 .(l C
18 .ps 12
19 .ft B
20 Vi/Ex Reference Manual
21 .ft
22 .ps
23 .sp
24 .i "Keith Bostic"
25 .sp
26 Computer Science Division
27 Department of Electrical Engineering and Computer Science
28 University of California, Berkeley
29 Berkeley, California  94720
30 .sp 1
31 .)l
32 .sp 3
33 .(l C
34 .i Abstract
35 .)l
36 .(q
37 .pp
38 This document is the reference guide for the 4.4BSD
39 implementations of
40 .EV nex nvi ,
41 which are implementations of the historic Berkeley
42 .EV ex vi
43 editors.
44 .)q
45 .sp 3
46 .(l C
47 .i Licensing
48 .)l
49 .sp
50 .lp
51 Copyright (c) 1991, 1992, 1993, 1994
52 .ti +5
53 The Regents of the University of California.  All Rights Reserved.
54 .lp
55 Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996
56 .ti +5
57 Keith Bostic.  All Rights Reserved.
58 .sp
59 .pp
60 The vi program is freely redistributable.  You are welcome to copy,
61 modify and share it with others under the conditions listed in the
62 LICENSE file.  If any company (not individual!) finds vi sufficiently
63 useful that you would have purchased it, or if any company wishes to
64 redistribute it, contributions to the authors would be appreciated.
65 .bp 2
66 .(l C
67 .i Acknowledgements
68 .)l
69 .sp
70 .(q
71 .pp
72 Bruce Englar encouraged the early development of the historic
73 .EV ex vi
74 editor.
75 Peter Kessler helped bring sanity to version 2's command layout.
76 Bill Joy wrote versions 1 and 2.0 through 2.7,
77 and created the framework that users see in the present editor.
78 Mark Horton added macros and other features and made
79 .EV ex vi
80 work on a large number of terminals and Unix systems.
81 .pp
82 .CO Nvi
83 is originally derived from software contributed to the University of
84 California, Berkeley by Steve Kirkendall, the author of the
85 .CO vi
86 clone
87 .CO elvis .
88 .pp
89 IEEE Standard Portable Operating System Interface for Computer
90 Environments (POSIX) 1003.2 style Regular Expression support was
91 done by Henry Spencer.
92 .pp
93 The curses library was originally done by Ken Arnold.
94 Scrolling and reworking for
95 .CO nvi
96 was done by Elan Amir.
97 .pp
98 George Neville-Neil added the Tcl interpreter,
99 and Sven Verdoolaege added the Perl interpreter.
100 .pp
101 Rob Mayoff added Cscope support.
102 .pp
103 The Institute of Electrical and Electronics Engineers has
104 given us permission to reprint portions of their documentation.
105 Portions of this document are reprinted and reproduced from
106 IEEE Std 1003.2-1992, IEEE Standard Portable Operating
107 System Interface for Computer Environments (POSIX),
108 copyright 1992 by the Institute of Electrical and Electronics
109 Engineers, Inc.
110 .pp
111 The financial support of UUNET Communications Services is gratefully
112 acknowledged.
113 .)q
114 .sy echo -n >index
115 .oh 'Vi/Ex Reference''USD:13-%'
116 .eh 'USD:13-%''Vi/Ex Reference'
117 .bp 4
118 .SH 1 Description
119 .pp
120 .CO Vi
121 is a screen oriented text editor.
122 .CO Ex
123 is a line-oriented text editor.
124 .CO Ex
125 and
126 .CO vi
127 are different interfaces to the same program,
128 and it is possible to switch back and forth during an edit session.
129 .CO View
130 is the equivalent of using the
131 .b \-R
132 (read-only) option of
133 .CO vi .
134 .pp
135 This reference manual is the one provided with the
136 .EV nex nvi
137 versions of the
138 .EV ex vi
139 text editors.
140 .EV Nex nvi
141 are intended as bug-for-bug compatible replacements for the original
142 Fourth Berkeley Software Distribution (4BSD)
143 .EV ex vi
144 programs.
145 This reference manual is accompanied by a traditional-style manual page.
146 That manual page describes the functionality found in
147 .EV ex vi
148 in far less detail than the description here.
149 In addition, it describes the system interface to
150 .EV ex vi ,
151 e.g. command line options, session recovery, signals,
152 environmental variables, and similar things.
153 .pp
154 This reference is intended for users already familiar with
155 .EV ex vi .
156 Anyone else should almost certainly read a good tutorial on the
157 editor first.
158 If you are in an unfamiliar environment,
159 and you absolutely have to get work done immediately,
160 see the section entitled
161 .QB "Fast Startup"
162 in the manual page.
163 It is probably enough to get you started.
164 .pp
165 There are a few features in
166 .EV nex nvi
167 that are not found in historic versions of
168 .EV ex vi .
169 Some of the more interesting of those features are briefly described
170 in the next section, entitled
171 .QB "Additional Features" .
172 For the rest of this document,
173 .EV nex nvi
174 is used only when it is necessary to distinguish it from the historic
175 implementations of
176 .EV ex vi .
177 .pp
178 Future versions of this software will be periodically made available
179 by anonymous ftp, and can be retrieved from
180 .LI ftp.cs.berkeley.edu ,
181 in the directory
182 .LI ucb/4bsd .
183 .SH 1 "Additional Features in Nex/Nvi"
184 .pp
185 There are a few features in
186 .EV nex nvi
187 that are not found in historic versions of
188 .EV ex vi .
189 Some of the more interesting of these are as follows:
190 .IP "8-bit clean data, large lines, files"
191 .EV Nex nvi
192 will edit any format file.
193 Line lengths are limited by available memory,
194 and file sizes are limited by available disk space.
195 The
196 .CO vi
197 text input mode command
198 .CO <control-X>
199 can insert any possible character value into the text.
200 .IP "Background and foreground screens"
201 The
202 .CO bg
203 command backgrounds the current screen, and the
204 .CO fg
205 command foregrounds backgrounded screens.
206 The
207 .CO display
208 command can be used to list the background screens.
209 .IP "Command Editing"
210 You can enter a normal editing window on the collected commands that
211 you've entered on the
212 .CO vi
213 colon command-line,
214 and then modify and/or execute the commands.
215 See the
216 .OP cedit
217 edit option for more information.
218 .IP "Displays"
219 The
220 .CO display
221 command can be used to display the current buffers, the backgrounded
222 screens, and the tags stack.
223 .IP "Extended Regular Expressions"
224 The
225 .CO extended
226 option causes Regular Expressions to be interpreted as as Extended
227 Regular Expressions, (i.e. \fIegrep\fP(1) style Regular Expressions).
228 .IP "File Name Completion"
229 It is possible to do file name completion and file name displays when
230 entering commands on the
231 .CO vi
232 colon command-line.
233 See the
234 .OP filec
235 option for more information.
236 .IP "Infinite undo"
237 Changes made during an edit session may be rolled backward and forward.
238 A
239 .CO \&.
240 command immediately after a
241 .CO u
242 command continues either forward or backward depending on whether the
243 .CO u
244 command was an undo or a redo.
245 .IP "Left-right scrolling"
246 The
247 .CO leftright
248 option causes
249 .CO nvi
250 to do left-right screen scrolling, instead of the traditional
251 .CO vi
252 line wrapping.
253 .IP "Message Catalogs"
254 It is possible to display informational and error messages in different
255 languages by providing a catalog of messages.
256 See the
257 .OP msgcat
258 option and the file
259 .LI "catalog/README"
260 for more information.
261 .IP "Incrementing numbers"
262 The
263 .CO \&#
264 command increments or decrements the number referenced by the cursor.
265 .IP "Previous file"
266 The
267 .CO previous
268 command edits the previous file from the argument list.
269 .IP "Scripting languages"
270 The
271 .CO ":pe[rl] cmd" ,
272 .CO ":perld[o] cmd"
273 and
274 .CO ":tc[l] cmd"
275 commands execute Perl and Tcl/Tk commands, respectively,
276 on lines from the edit buffer.
277 See the
278 .QB "Scripting Languages"
279 section and the specific commands for more information.
280 .\".IP "Shell screens"
281 .\"The
282 .\".CO ":sc[ript] [file ...]"
283 .\"command runs a shell in the screen.
284 .\"Editing is unchanged, with the exception that a \fC<carriage-return>\fP
285 .\"enters the current line (stripped of any prompt) as input to the
286 .\"shell.
287 .IP "Split screens"
288 The
289 .CO Edit ,
290 .CO Ex ,
291 .CO Next ,
292 .CO Previous ,
293 .CO Tag
294 and
295 .CO Visual
296 (in
297 .CO vi
298 mode) commands divide the screen into multiple editing regions and
299 then perform their normal function in a new screen area.
300 The
301 .CO <control-W>
302 command rotates between the foreground screens.
303 The
304 .CO resize
305 command can be used to grow or shrink a particular screen.
306 .IP "Tag stacks"
307 Tags are now maintained in a stack.
308 The
309 .CO <control-T>
310 command returns to the previous tag location.
311 The
312 .CO tagpop
313 command returns to the most recent tag location by default, or,
314 optionally to a specific tag number in the tag stack,
315 or the most recent tag from a specified file.
316 The
317 .CO display
318 command can be used to list the tags stack.
319 The
320 .CO tagtop
321 command returns to the top of the tag stack.
322 .IP "Usage information"
323 The
324 .CO exusage
325 and
326 .CO viusage
327 commands provide usage information for all of the
328 .CO ex
329 and
330 .CO vi
331 commands by default, or, optionally, for a specific command or key.
332 .IP "Word search"
333 The
334 .CO <control-A>
335 command searches for the word referenced by the cursor.
336 .SH 1 "Startup Information"
337 .pp
338 .EV Ex vi
339 interprets one of two possible environmental variables and reads up to
340 three of five possible files during startup.
341 The variables and files are expected to contain
342 .CO ex
343 commands, not
344 .CO vi
345 commands.
346 In addition, they are interpreted
347 .i before
348 the file to be edited is read, and therefore many
349 .CO ex
350 commands may not be used.
351 Generally, any command that requires output to the screen or that
352 needs a file upon which to operate, will cause an error if included
353 in a startup file or environmental variable.
354 .pp
355 Because the
356 .CO ex
357 command set supported by
358 .EV nex nvi
359 is a superset of the command set supported by historical implementations of
360 .CO ex ,
361 .EV nex nvi
362 can use the startup files created for the historical implementations,
363 but the converse may not be true.
364 .pp
365 If the
366 .b \-s
367 (the historic \- option)
368 is specified, or if standard input is redirected from a file,
369 all environmental variables and startup files are ignored.
370 .pp
371 Otherwise, startup files and environmental variables are handled
372 in the following order:
373 .np
374 The file
375 .LI /etc/vi.exrc
376 is read,
377 as long as it is owned by root or the effective user ID of the user.
378 .np
379 The environmental variable
380 .LI NEXINIT
381 (or the variable
382 .LI EXINIT ,
383 if
384 .LI NEXINIT
385 is not set) is interpreted.
386 .np
387 If neither
388 .LI NEXINIT
389 or
390 .LI EXINIT
391 was set, and the
392 .LI HOME
393 environmental variable is set, the file
394 .LI $HOME/.nexrc
395 (or the file
396 .LI $HOME/.exrc ,
397 if
398 .LI $HOME/.nexrc
399 does not exist) is read,
400 as long as the effective user ID of the user is root or is the same as
401 the owner of the file.
402 .sp
403 When the $HOME directory is being used for both
404 .EV nex nvi
405 and an historic implementation of
406 .EV ex vi ,
407 a possible solution is to put
408 .EV nex nvi
409 specific commands in the
410 .LI \&.nexrc
411 file, along with a
412 .CO ":source $HOME/.exrc"
413 command to read in the commands common to both implementations.
414 .np
415 If the
416 .OP exrc
417 option was turned on by one of the previous startup information
418 sources, the file
419 .LI \&.nexrc
420 (or the file
421 .LI \&.exrc ,
422 if
423 .LI \&.nexrc
424 does not exist) is read, as long as the effective user ID of the user
425 is the same as the owner of the file.
426 .pp
427 No startup file is read if it is writable by anyone other than its owner.
428 .pp
429 It is not an error for any of the startup environmental variables or files
430 not to exist.
431 .pp
432 Once all environmental variables are interpreted,
433 and all startup files are read,
434 the first file to be edited is read in (or a temporary file is created).
435 Then, any commands specified using the
436 .b \-c
437 option are executed, in the context of that file.
438 .SH 1 "Recovery"
439 .pp
440 There is no recovery program for
441 .EV nex nvi ,
442 nor does
443 .EV nex nvi
444 run setuid.
445 Recovery files are created readable and writable by the owner only.
446 Users may recover any file which they can read,
447 and the superuser may recover any edit session.
448 .pp
449 Edit sessions are backed by files in the directory named by the
450 .OP recdir
451 option (the directory
452 .LI /var/tmp/vi.recover
453 by default), and are named
454 .QC vi.XXXXXX ,
455 where
456 .QC XXXXXX
457 is a number related to the process ID.
458 When a file is first modified,
459 a second recovery file containing an email message for the user is created,
460 and is named
461 .QC recover.XXXXXX ,
462 where, again,
463 .QC XXXXXX
464 is associated with the process ID.
465 Both files are removed at the end of a normal edit session,
466 but will remain if the edit session is abnormally terminated
467 or the user runs the
468 .CO ex
469 .CO preserve
470 command.
471 .pp
472 The
473 .OP recdir
474 option may be set in either the user's or system's startup information,
475 changing the recovery directory.
476 (Note, however, that if a memory based file system is used as the backup
477 directory, each system reboot will delete all of the recovery files!
478 The same caution applies to directories such as
479 .LI /tmp
480 which are cleared of their contents by a system reboot, or
481 .LI /usr/tmp
482 which is periodically cleared of old files on many systems.)
483 .pp
484 The recovery directory should be owned by root, or at least by a pseudo-user.
485 In addition, if directory
486 .QQ sticky-bit
487 semantics are available, the directory should have the sticky-bit
488 set so that files may only be removed by their owners.
489 The recovery directory must be read, write, and executable by any user,
490 i.e. mode 1777.
491 .pp
492 If the recovery directory does not exist,
493 .EV ex vi
494 will attempt to create it.
495 This can result in the recovery directory being owned by a normal user,
496 which means that that user will be able to remove other user's recovery
497 and backup files.
498 This is annoying, but is not a security issue as the user cannot
499 otherwise access or modify the files.
500 .pp
501 The recovery file has all of the necessary information in it to enable the
502 user to recover the edit session.
503 In addition, it has all of the necessary email headers for
504 .XR sendmail 8 .
505 When the system is rebooted, all of the files in
506 .LI /var/tmp/vi.recover
507 named
508 .QC recover.XXXXXX
509 should be sent to their owners, by email, using the
510 .b \-t
511 option of
512 .CO sendmail
513 (or a similar mechanism in other mailers).
514 If
515 .EV ex vi
516 receives a hangup (SIGHUP) signal, or the user executes the
517 .CO ex
518 .CO preserve
519 command,
520 .EV ex vi
521 will automatically email the recovery information to the user.
522 .pp
523 If your system does not have the
524 .CO sendmail
525 utility (or a mailer program which supports its interface)
526 the source file
527 .LI nvi/common/recover.c
528 will have to be modified to use your local mail delivery programs.
529 Note, if
530 .EV nex nvi
531 is changed to use another mailer,
532 it is important to remember that the owner of the file given to
533 the mailer is the
534 .EV nex nvi
535 user, so nothing in the file should be trusted as it may have been
536 modified in an effort to compromise the system.
537 .pp
538 Finally, the owner execute bit is set on backup files when they are
539 created, and unset when they are first modified, e.g. backup files
540 that have no associated email recovery file will have this bit set.
541 (There is also a small window where empty files can be created and
542 not yet have this bit set.
543 This is due to the method in which the files are created.)
544 Such files should be deleted when the system reboots.
545 .pp
546 A simple way to do this cleanup is to run the Bourne shell script
547 .CO recover ,
548 from your
549 .LI /etc/rc.local
550 (or other system startup) file.
551 The script should work with the historic Bourne shell,
552 a POSIX 1003.2 shell or the Korn shell.
553 The
554 .CO recover
555 script is installed as part of the
556 .EV nex nvi
557 installation process.
558 .pp
559 Consult the manual page for details on recovering preserved or
560 aborted editing sessions.
561 .SH 1 "Sizing the Screen"
562 .pp
563 The size of the screen can be set in a number of ways.
564 .EV Ex vi
565 takes the following steps until values are obtained for both the
566 number of rows and number of columns in the screen.
567 .np
568 If the environmental variable
569 .LI LINES
570 exists,
571 it is used to specify the number of rows in the screen.
572 .np
573 If the environmental variable
574 .LI COLUMNS
575 exists,
576 it is used to specify the number of columns in the screen.
577 .np
578 The TIOCGWINSZ
579 .XR ioctl 2
580 is attempted on the standard error file descriptor.
581 .np
582 The termcap entry (or terminfo entry on System V machines)
583 is checked for the
584 .QQ li
585 entry (rows) and the
586 .QQ co
587 entry (columns).
588 .np
589 The number of rows is set to 24, and the number of columns is set to 80.
590 .pp
591 If a window change size signal (SIGWINCH) is received,
592 the new window size is retrieved using the TIOCGWINSZ
593 .XR ioctl 2
594 call, and all other information is ignored.
595 .SH 1 "Character Display"
596 .pp
597 In both
598 .CO ex
599 and
600 .CO vi
601 printable characters as defined by
602 .XR isprint 3
603 are displayed using the local character set.
604 .pp
605 Non-printable characters, for which
606 .XR iscntrl 3
607 returns true, and which are less than octal \e040,
608 are displayed as the string
609 .QT ^<character> ,
610 where
611 .LI <character>
612 is the character that is the original character's value offset from the
613 .QT @
614 character.
615 For example, the octal character \e001 is displayed as
616 .QT ^A .
617 If
618 .XR iscntrl 3
619 returns true for the octal character \e177,
620 it is displayed as the string
621 .QT ^? .
622 All other characters are displayed as either hexadecimal values,
623 in the form
624 .QT "0x<high-halfbyte> ... 0x<low-halfbyte>" ,
625 or as octal values, in the form
626 .QT "\e<high-one-or-two-bits> ... \e<low-three-bits>" .
627 The display of unknown characters is based on the value of the
628 .OP octal
629 option.
630 .pp
631 In
632 .CO vi
633 command mode, the cursor is always positioned on the last column of
634 characters which take up more than one column on the screen.
635 In
636 .CO vi
637 text input mode, the cursor is positioned on the first column of
638 characters which take up more than one column on the screen.
639 .SH 1 "Multiple Screens"
640 .pp
641 .CO Nvi
642 supports multiple screens by dividing the window into regions.
643 It also supports stacks of screens by permitting the user to change
644 the set of screens that are currently displayed.
645 .pp
646 The
647 .CO Edit ,
648 .CO Ex ,
649 .CO Fg ,
650 .CO Next ,
651 .CO Previous ,
652 .CO Tag
653 and
654 .CO Visual
655 (in
656 .CO vi
657 mode)
658 commands divide the current screen into two regions of approximately
659 equal size and then perform their usual action in a new screen area.
660 If the cursor is in the lower half of the screen, the screen will split
661 up, i.e. the new screen will be above the old one.
662 If the cursor is in the upper half of the screen, the new screen will be
663 below the old one.
664 .pp
665 When more than one screen is editing a file, changes in any screen are
666 reflected in all other screens editing the same file.
667 Exiting a screen without saving any changes (or explicitly discarding
668 them) is permitted until the last screen editing the file is exited,
669 at which time the changes must be saved or discarded.
670 .pp
671 The
672 .CO resize
673 command permits resizing of individual screens.
674 Screens may be grown, shrunk or set to an absolute number of rows.
675 .pp
676 The
677 .CO ^W
678 command is used to switch between screens.
679 Each
680 .CO ^W
681 moves to the next lower screen in the window, or to the first screen
682 in the window if there are no lower screens.
683 .pp
684 The
685 .CO bg
686 command
687 .QQ backgrounds
688 the current screen.
689 The screen disappears from the window,
690 and the rows it occupied are taken over by a neighboring screen.
691 It is an error to attempt to background the only screen in the window.
692 .pp
693 The
694 .CO "display screens"
695 command displays the names of the files associated with the current
696 backgrounded screens in the window.
697 .pp
698 The
699 .CO "fg [file]"
700 command moves the specified screen from the list of backgrounded screens
701 to the foreground.
702 If no file argument is specified, the first screen on the list is
703 foregrounded.
704 By default,
705 foregrounding consists of backgrounding the current screen,
706 and replacing its space in the window with the foregrounded screen.
707 .pp
708 Capitalizing the first letter of the command, i.e.
709 .CO Fg ,
710 will foreground the backgrounded screen in a new screen instead of
711 swapping it with the current screen.
712 .pp
713 If the last foregrounded screen in the window is exited,
714 and there are backgrounded screens,
715 the first screen on the list of backgrounded screens takes over the window.
716 .SH 1 "Tags, Tag Stacks, and Cscope"
717 .pp
718 .CO Nvi
719 supports the historic
720 .CO vi
721 tag command
722 .CO <control-]> ,
723 and the historic
724 .CO ex
725 tag command
726 .CO tag .
727 These commands change the current file context to a new location,
728 based on information found in the
729 .LI tags
730 files.
731 If you are unfamiliar with these commands,
732 you should review their description in the
733 .CO ex
734 and
735 .CO vi
736 commands section of this manual.
737 For additional information on tags files,
738 see the discussion of the
739 .OP tags
740 edit option and the system
741 .XR ctags 1
742 manual page.
743 .pp
744 In addition,
745 .CO nvi
746 supports the notion of
747 .QQ "tags stacks" ,
748 using the
749 .CO <control-T>
750 command.
751 The
752 .CO <control-T>
753 command returns the user to the previous context, i.e.,
754 the last place from which a
755 .CO <control-]>
756 or
757 .CO "tag"
758 command was entered.
759 These three commands provide the basic functionality which allows you
760 to use
761 .CO vi
762 to review source code in a structured manner.
763 .pp
764 .CO Nvi
765 also provides two other basic
766 .CO ex
767 commands for tag support:
768 .CO tagpop
769 and
770 .CO tagtop .
771 The
772 .CO tagpop
773 command is identical to the
774 .CO <control-T>
775 command,
776 with the additional functionality that you may specify that modifications
777 to the current file are to be discarded.
778 This cannot be done using the
779 .CO <control-T>
780 command.
781 The
782 .CO tagtop
783 command discards all of the contexts that have been pushed onto the tag
784 stack, returning to the context from which the first
785 .CO <control-]>
786 or
787 .CO tag
788 command was entered.
789 .pp
790 The historic
791 .XR ctags 1
792 tags file format supports only a single location per tag,
793 normally the function declaration or structure or string definition.
794 More sophisticated source code tools often provide multiple locations
795 per tag, e.g.,
796 a list of the places from which a function is called or a string
797 definition is used.
798 An example of this functionality is the System V source code tool,
799 .CO cscope .
800 .sp
801 .CO Cscope
802 creates a database of information on source code files,
803 and supports a query language for that information as described in the
804 .XR cscope 1
805 manual page.
806 .CO Nvi
807 contains an interface to the
808 .CO cscope
809 query language which permits you to query
810 .CO cscope
811 and then sequentially step through the locations in the sources files which
812 .CO cscope
813 returns.
814 There are two
815 .CO nvi
816 commands which support this ability to step through multiple locations.
817 They are the
818 .CO ex
819 commands
820 .CO tagnext
821 and
822 .CO tagprev .
823 The
824 .CO tagnext
825 command moves to the next location for the current tag.
826 The
827 .CO tagprev
828 command moves to the previous location for the current tag.
829 (See the
830 .CO tagnext
831 and
832 .CO tagprev
833 command discussion in the
834 .CO ex
835 commands section of this manual for more information.)
836 At any time during this sequential walk,
837 you may use the
838 .CO <control-]> ,
839 .CO tag
840 or
841 .CO cscope
842 commands to move to a new tag context, and then use the
843 .CO <control-T>
844 or
845 .CO tagpop
846 commands to return and continue stepping through the locations for this
847 tag.
848 This is similar to the previous model of a simple tag stack,
849 except that each entry in the tag stack may have more than one file context
850 that is of interest.
851 .pp
852 Although there is no widely distributed version of
853 .XR ctags 1
854 that creates tags files with multiple locations per tag,
855 .CO nvi
856 has been written to understand the obvious extension to the historic
857 tags file format, i.e., more than a single line in the tags file with
858 the same initial tag name.
859 If you wish to extend your
860 .CO ctags 
861 implementation or other tool with which you build tags files,
862 this extension should be simple and will require no changes to
863 .CO nvi .
864 .pp
865 The
866 .CO nvi
867 and
868 .CO cscope
869 interface is based on the new
870 .CO ex
871 command
872 .CO cscope ,
873 which has five subcommands:
874 .CO add ,
875 .CO find ,
876 .CO help ,
877 .CO kill
878 and
879 .CO reset .
880 The subcommand
881 .CO find
882 itself has eight subcommands:
883 .CO \&c ,
884 .CO \&d ,
885 .CO \&e ,
886 .CO \&f ,
887 .CO \&g ,
888 .CO \&i ,
889 .CO \&s
890 and
891 .CO \&t .
892 .pp
893 .IP "cs[cope] a[dd] file"
894 The
895 .CO add
896 command attaches to the specified
897 .CO cscope
898 database.
899 The file name is expanded using the standard filename expansions.
900 If
901 .CO file
902 is a directory, the file
903 .QQ cscope.out
904 in that directory is used as the database.
905 .pp
906 After
907 .CO nvi
908 attaches to a new database,
909 all subsequent
910 .CO cscope
911 queries will be asked of that database.
912 The result of any single query is the collection of response to the query
913 from all of the attached databases.
914 .sp
915 If the
916 .QQ CSCOPE_DIRS
917 environmental variable is set when
918 .CO nvi
919 is run,
920 it is expected to be a <colon> or <blank>-separated list of
921 .CO cscope
922 databases or directories containing
923 .CO cscope
924 databases, to which the user wishes to attach.
925 .IP ":cs[cope] f[ind] c|d|e|f|g|i|s|t buffer|pattern"
926 The
927 .CO find
928 command is the
929 .CO cscope
930 query command for
931 .CO nvi .
932 For this command,
933 .CO nvi
934 queries all attached
935 .CO cscope
936 databases for the pattern.
937 If the pattern is a double-quote character followed by a valid buffer
938 name (e.g.,
939 .LI """<character>" ), 
940 then the contents of the named buffer are used as the pattern.
941 Otherwise, the pattern is a Regular Expression.
942 .sp
943 The
944 .CO find
945 command pushes the current location onto the tags stack,
946 and switches to the first location resulting from the query,
947 if the query returned at least one result.
948 .sp
949 File names returned by the
950 .CO cscope
951 query, if not absolute paths, are searched for relative to the directory
952 where the
953 .CO cscope
954 database is located.
955 In addition, if the file
956 .QQ cscope.tpath
957 appears in the same directory as the
958 .CO cscope
959 database,
960 it is expected to contain a colon-separated list of directory names
961 where files referenced by its associated
962 .CO cscope
963 database may be found.
964 .sp
965 The
966 .CO find
967 subcommand is one of the following:
968 .SS
969 .SP \&c
970 Find callers of the name.
971 .SP \&d
972 Find all function calls made from name.
973 .SP \&e
974 Find pattern.
975 .SP \&f
976 Find files with name as substring.
977 .SP \&g
978 Find definition of name.
979 .SP \&i
980 Find files #including name.
981 .SP \&s
982 Find all uses of name.
983 .SP \&t
984 Find assignments to name.
985 .SE
986 .IP ":cs[cope] h[elp] [command]"
987 List the
988 .CO cscope
989 commands,
990 or optionally list usage help for any single
991 .CO cscope
992 command.
993 .IP ":display c[onnections]"
994 Display the list of
995 .CO cscope
996 databases to which
997 .CO nvi
998 is currently connected.
999 .IP ":cs[cope] k[ill] #"
1000 Disconnect from a specific
1001 .CO cscope
1002 database.
1003 The connection number is the one displayed by the
1004 .CO ex
1005 .CO "display connections"
1006 command.
1007 .IP ":cs[cope] r[eset]"
1008 Disconnect from all attached
1009 .CO cscope
1010 databases.
1011 .pp
1012 Cscope is not freely redistributable software,
1013 but is fairly inexpensive and easily available.
1014 To purchase a copy of
1015 .CO cscope ,
1016 see http://www.att.com/ssg/products/toolchest.html.
1017 .SH 1 "Regular Expressions and Replacement Strings"
1018 .pp
1019 Regular expressions are used in line addresses,
1020 as the first part of the
1021 .CO ex
1022 .CO substitute ,
1023 .CO global ,
1024 and
1025 .CO v
1026 commands, and in search patterns.
1027 .pp
1028 The regular expressions supported by
1029 .EV ex vi
1030 are, by default, the Basic Regular Expressions (BRE's) described in the
1031 IEEE POSIX Standard 1003.2.
1032 The
1033 .OP extended
1034 option causes all regular expressions to be interpreted as the Extended
1035 Regular Expressions (ERE's) described by the same standard.
1036 (See
1037 .XR re_format 7
1038 for more information.)
1039 Generally speaking, BRE's are the Regular Expressions found in
1040 .XR ed 1
1041 and
1042 .XR grep 1 ,
1043 and ERE's are the Regular Expressions found in
1044 .XR egrep 1 .
1045 .pp
1046 The following is not intended to provide a description of Regular
1047 Expressions.
1048 The information here only describes strings and characters which
1049 have special meanings in the
1050 .EV ex vi
1051 version of RE's,
1052 or options which change the meanings of characters that normally
1053 have special meanings in RE's.
1054 .np
1055 An empty RE (e.g.
1056 .QT //
1057 or
1058 .QT ??
1059 is equivalent to the last RE used.
1060 .np
1061 The construct
1062 .QT \e<
1063 matches the beginning of a word.
1064 .np
1065 The construct
1066 .QT \e>
1067 matches the end of a word.
1068 .np
1069 The character
1070 .QT ~
1071 matches the replacement part of the last
1072 .CO substitute
1073 command.
1074 .pp
1075 When the
1076 .OP magic
1077 option is
1078 .i not
1079 set, the only characters with special meanings are a
1080 .QT ^
1081 character at the beginning of an RE, a
1082 .QT $
1083 character at the end of an RE, and the escaping character
1084 .QT \e .
1085 The characters
1086 .QT \&. ,
1087 .QT * ,
1088 .QT [
1089 and
1090 .QT ~
1091 are treated as ordinary characters unless preceded by a
1092 .QT \e ;
1093 when preceded by a
1094 .QT \e
1095 they regain their special meaning.
1096 .pp
1097 Replacement strings are the second part of a
1098 .CO substitute
1099 command.
1100 .pp
1101 The character
1102 .QT &
1103 (or
1104 .QT \e&
1105 if the
1106 .OP magic
1107 option is
1108 .i not
1109 set) in the replacement string stands for the text matched by the RE
1110 that is being replaced.
1111 The character
1112 .QT ~
1113 (or
1114 .QT \e~
1115 if the
1116 .OP magic
1117 option is
1118 .i not
1119 set) stands for the replacement part of the previous
1120 .CO substitute
1121 command.
1122 It is only valid after a
1123 .CO substitute
1124 command has been performed.
1125 .pp
1126 The string
1127 .QT \e# ,
1128 where
1129 .QT #
1130 is an integer value from 1 to 9, stands for the text matched by
1131 the portion of the RE enclosed in the
1132 .QT # 'th
1133 set of escaped parentheses, e.g.
1134 .QT \e(
1135 and
1136 .QT \e) .
1137 For example,
1138 .QT "s/abc\e(.*\e)def/\e1/"
1139 deletes the strings
1140 .QT abc
1141 and
1142 .QT def
1143 from the matched pattern.
1144 .pp
1145 The strings
1146 .QT \el ,
1147 .QT \eu ,
1148 .QT \eL
1149 and
1150 .QT \eU
1151 can be used to modify the case of elements in the replacement string.
1152 The string
1153 .QT \el
1154 causes the next character to be converted to lowercase;
1155 the string
1156 .QT \eu
1157 behaves similarly, but converts to uppercase
1158 (e.g.
1159 .LI s/abc/\eU&/
1160 replaces the string
1161 .LI abc
1162 with
1163 .LI ABC ).
1164 The string
1165 .QT \eL
1166 causes characters up to the end of the string or the next occurrence
1167 of the strings
1168 .QT \ee
1169 or
1170 .QT \eE
1171 to be converted to lowercase;
1172 the string
1173 .QT \eU
1174 behaves similarly, but converts to uppercase.
1175 .pp
1176 If the entire replacement pattern is
1177 .QT % ,
1178 then the last replacement pattern is used again.
1179 .pp
1180 In
1181 .CO vi ,
1182 inserting a
1183 .LI <control-M>
1184 into the replacement string will cause
1185 the matched line to be split into two lines at that point.
1186 (The
1187 .LI <control-M>
1188 will be discarded.)
1189 .SH 1 "Scripting Languages"
1190 .pp
1191 The
1192 .CO nvi
1193 editor currently supports two scripting languages, Tcl/Tk and Perl.
1194 (Note that Perl4 isn't sufficient, and that the Perl5 used must be
1195 version 5.002 or later.
1196 See the
1197 .QB "Building Nvi"
1198 section for more information.
1199 .pp
1200 The scripting language interface is still being worked on,
1201 therefore the following information is probably incomplete,
1202 probably wrong in cases, and likely to change.
1203 See the
1204 .LI perl_api
1205 and
1206 .LI tcl_api
1207 source directories for more information.
1208 As a quick reference, the following function calls are provided for
1209 both the Perl and Tcl interfaces.
1210 The Perl interface uses a slightly different naming convention,
1211 e.g. ``viFindScreen'' is named ``VI::FindScreen''.
1212 .IP "viFindScreen file"
1213 Return the
1214 .LI "screenId" associated with
1215 .LI file .
1216 .IP "viAppendLine screenId lineNumber text"
1217 Append
1218 .LI text
1219 as a new line after line number
1220 .LI lineNumber ,
1221 in the screen
1222 .LI screenId .
1223 .IP "viDelLine screenId lineNum"
1224 Delete the line
1225 .LI lineNumber
1226 from the screen
1227 .LI screenId .
1228 .IP "viGetLine screenId lineNumber"
1229 Return the line
1230 .LI lineNumber
1231 from the screen
1232 .LI screenId .
1233 .IP "viInsertLine screenId lineNumber text"
1234 Insert
1235 .LI text
1236 as a new line before line number
1237 .LI lineNumber
1238 in the screen
1239 .LI screenId .
1240 .IP "viLastLine screenId"
1241 Return the line number of the last line in the screen
1242 .LI screenId .
1243 .IP "viSetLine screenId lineNumber text"
1244 Change the line
1245 .LI lineNumber
1246 in the screen
1247 .LI screenId
1248 to match the specified
1249 .LI text .
1250 .IP "viGetMark screenId mark"
1251 Return the current line and column for the specified
1252 .LI mark
1253 from the screen
1254 .LI screenId .
1255 .IP "viSetMark screenId mark line column"
1256 Set the specified
1257 .LI mark
1258 to be at line
1259 .LI line ,
1260 column
1261 .LI column ,
1262 in the screen
1263 .LI screenId .
1264 .IP "viGetCursor screenId"
1265 Return the current line and column for the cursor in the screen
1266 .LI screenId .
1267 .IP "viSetCursor screenId line column"
1268 Set the cursor in the screen
1269 .LI screenId
1270 to the specified
1271 .LI line
1272 and
1273 .LI column .
1274 .IP "viMsg screenId text"
1275 Display the specified
1276 .LI text
1277 as a vi message in the screen
1278 .LI screenId .
1279 .IP "viNewScreen screenId [file]"
1280 Create a new screen.
1281 .IP "viEndScreen screenId"
1282 Exit the screen 
1283 .LI screenId .
1284 .IP "viSwitchScreen screenId screenId"
1285 Switch from the screen
1286 .LI screenId
1287 to the screen
1288 .LI screenId .
1289 .IP "viMapKey screenId key tclproc"
1290 Map the specified
1291 .LI key
1292 in the screen
1293 .LI screenId
1294 to the Tcl procedure
1295 .LI tclproc .
1296 .IP "viUnmMapKey screenId key"
1297 Unmap the specified
1298 .LI key
1299 in the screen
1300 .LI screenId
1301 .IP "viGetOpt screenId option"
1302 Return the value of the specified
1303 .LI option
1304 from the screen
1305 .LI screenId .
1306 .IP "viSetOpt screenId command"
1307 Set one or more options in the screen
1308 .LI screenId .
1309 .SH 1 "General Editor Description"
1310 .pp
1311 When
1312 .CO ex
1313 or
1314 .CO vi
1315 are executed,
1316 the text of a file is read (or a temporary file is created),
1317 and then all editing changes happen within the context of the
1318 copy of the file.
1319 .i "No changes affect the actual file until the file is written out" ,
1320 either using a write command or another command which is affected by the
1321 .OP autowrite
1322 option.
1323 .pp
1324 All files are locked (using the
1325 .XR flock 2
1326 or
1327 .XR fcntl 2
1328 interfaces) during the edit session,
1329 to avoid inadvertently making modifications to multiple copies of the file.
1330 If a lock cannot be obtained for a file because it is locked by another
1331 process, the edit session is read-only (as if the
1332 .OP readonly
1333 option or the
1334 .b \-R
1335 flag had been specified).
1336 If a lock cannot be obtained for other reasons, the edit session will
1337 continue, but the file status information
1338 (see the
1339 .CO <control-G>
1340 command) will reflect this fact.
1341 .pp
1342 Both
1343 .CO ex
1344 and
1345 .CO vi
1346 are modeful editors, i.e. they have two modes,
1347 .QQ command
1348 mode and
1349 .QQ "text input"
1350 mode.
1351 The former is intended to permit you to enter commands which modifies
1352 already existing text.
1353 The latter is intended to permit you to enter new text.
1354 When
1355 .CO ex
1356 first starts running, it is in command mode, and usually displays a prompt
1357 (see the
1358 .OP prompt
1359 option for more information).
1360 The prompt is a single colon
1361 .PQ :
1362 character.
1363 There are three commands that switch
1364 .CO ex
1365 into text input mode:
1366 .CO append ,
1367 .CO change
1368 and
1369 .CO insert .
1370 Once in input mode, entering a line containing only a single period
1371 .PQ \&.
1372 ends text input mode and returns to command mode,
1373 where the prompt is redisplayed.
1374 .pp
1375 When
1376 .CO vi
1377 first starts running, it is in command mode as well.
1378 There are eleven commands that switch
1379 .CO vi
1380 into text input mode:
1381 .CO A ,
1382 .CO a ,
1383 .CO C ,
1384 .CO c ,
1385 .CO I ,
1386 .CO i ,
1387 .CO O ,
1388 .CO o ,
1389 .CO R ,
1390 .CO S
1391 and
1392 .CO s .
1393 Once in input mode, entering an
1394 .LI <escape>
1395 character ends text input mode and returns to command mode.
1396 .pp
1397 .EV Ex vi
1398 present three different interfaces to editing a file.
1399 .CO Ex
1400 presents a line oriented interface.
1401 .CO Vi
1402 presents a full screen display oriented interface,
1403 also known as
1404 .QQ "visual mode" .
1405 In addition, there is a third mode,
1406 .QQ "open mode" ,
1407 which is line oriented,
1408 but supports cursor movement and editing within the displayed line,
1409 similarly to visual mode.
1410 Open mode is not yet implemented in
1411 .CO nvi .
1412 .pp
1413 The following words have special meanings in both the
1414 .CO ex
1415 and
1416 .CO vi
1417 command descriptions:
1418 .KY <interrupt>
1419 .IP <interrupt>
1420 The interrupt character is used to interrupt the current operation.
1421 Normally
1422 .LI <control-C> ,
1423 whatever character is set for the current terminal is used.
1424 .KY "<literal-next>"
1425 .IP "<literal-next>"
1426 The literal next character is used to escape the subsequent character
1427 from any special meaning.
1428 This character is always
1429 .LI <control-V> .
1430 If the terminal is not set up to do XON/XOFF flow control,
1431 then
1432 .LI <control-Q>
1433 is used to mean literal next as well.
1434 .KY "current pathname"
1435 .IP "current pathname"
1436 The pathname of the file currently being edited by vi.
1437 When the percent character
1438 .PQ %
1439 appears in a file name entered as part of an
1440 .CO ex
1441 command argument, it is replaced by the current pathname.
1442 (The
1443 .QT %
1444 character can be escaped by preceding it with a backslash.)
1445 .KY "alternate pathname"
1446 .IP "alternate pathname"
1447 The name of the last file name mentioned in an
1448 .CO ex
1449 command, or,
1450 the previous current pathname if the last file mentioned
1451 becomes the current file.
1452 When the hash mark character
1453 .PQ #
1454 appears in a file name entered as part of an
1455 .CO ex
1456 command argument, it is replaced by the alternate pathname.
1457 (The
1458 .QT #
1459 character can be escaped by preceding it with a backslash.)
1460 .KY buffer
1461 .IP buffer
1462 One of a number of named areas for saving copies of text.
1463 Commands that change or delete text can save the changed or deleted
1464 text into a specific buffer, for later use, if the command allows
1465 it (i.e. the
1466 .CO ex
1467 .CO change
1468 command cannot save the changed text in a named buffer).
1469 Buffers are named with a single character, preceded by a double quote,
1470 e.g.
1471 .LI """<character>"
1472 in
1473 .CO vi
1474 and
1475 without the double quote, e.g.
1476 .LI <character> ,
1477 in
1478 .CO ex .
1479 (The double quote isn't necessary for
1480 .CO ex
1481 because buffers names are denoted by their position in the command line.)
1482 Historic implementations of
1483 .EV ex vi
1484 limited
1485 .LI <character>
1486 to the alphanumeric characters;
1487 .EV nex nvi
1488 permits the use of any character without another meaning in the position
1489 where a buffer name is expected.
1490 .sp
1491 Buffers named by uppercase characters are the same as buffers
1492 named by lowercase characters, e.g. the buffer named by the
1493 English character
1494 .QT A
1495 is the same as the buffer named by the character
1496 .QT a ,
1497 with the exception that, if the buffer contents are being changed (as
1498 with a text deletion or
1499 .CO vi
1500 .CO change
1501 command), the text is
1502 .i appended
1503 to the buffer, instead of replacing the current contents.
1504 .sp
1505 The buffers named by the numeric characters (in English,
1506 .QT 1
1507 through
1508 .QT 9 ),
1509 are special.
1510 If a region of text including characters from more than one line,
1511 or a single line of text specified by using a line-oriented motion,
1512 is changed or deleted in the file using the
1513 .CO vi
1514 .CO change
1515 or
1516 .CO delete
1517 commands, a copy of the text is placed into the numeric buffer
1518 .QT 1 ,
1519 regardless of the user specifying another buffer in which to save it.
1520 In addition, there are a few commands which, when used as a
1521 .LI motion
1522 with the
1523 .CO vi
1524 .CO change
1525 and
1526 .CO delete
1527 commands,
1528 .i always
1529 copy the specified region of text into the numeric buffers regardless
1530 of the region including characters from more than one line.
1531 These commands are:
1532 .sp
1533 .ne 3v
1534 .ft C
1535 .TS
1536 r r r r.
1537 <control-A>     %       (       )
1538 `<character>    /       ?       N
1539 n       {       }
1540 .TE
1541 .ft R
1542 .sp
1543 Before this copy is done, the previous contents of buffer
1544 .QT 1
1545 are moved into buffer
1546 .QT 2 ,
1547 .QT 2
1548 into buffer
1549 .QT 3 ,
1550 and so on.
1551 The contents of buffer
1552 .QT 9
1553 are discarded.
1554 In
1555 .CO vi ,
1556 text may be explicitly stored into the numeric buffers.
1557 In this case, the buffer rotation described above occurs before the
1558 replacement of the buffer's contents.
1559 The numeric buffers are only available in
1560 .LI visual
1561 and
1562 .LI open
1563 modes,
1564 and are not accessible by
1565 .CO ex
1566 in any way, although changed and deleted text is still stored there
1567 while in
1568 .CO ex
1569 mode.
1570 .sp
1571 When a
1572 .CO vi
1573 command synopsis shows both a
1574 .LI [buffer]
1575 and a
1576 .LI [count] ,
1577 they may be presented in any order.
1578 .sp
1579 Finally, all buffers are either
1580 .QQ line
1581 or
1582 .QQ character
1583 oriented.
1584 All
1585 .CO ex
1586 commands which store text into buffers are line oriented.
1587 Some
1588 .CO vi
1589 commands which store text into buffers are line oriented,
1590 and some are character oriented; the description for each applicable
1591 .CO vi
1592 command notes whether text copied into buffers using the command
1593 is line or character oriented.
1594 In addition, the
1595 .CO vi
1596 command
1597 .CO "display buffers"
1598 displays the current orientation for each buffer.
1599 Generally, the only importance attached to this orientation is that
1600 if the buffer is subsequently inserted into the text, line oriented
1601 buffers create new lines for each of the lines they contain, and
1602 character oriented buffers create new lines for any lines
1603 .i other
1604 than the first and last lines they contain.
1605 The first and last lines are inserted into the text at the current
1606 cursor position, becoming part of the current line.
1607 If there is more than one line in the buffer, however, the current
1608 line itself will be split.
1609 .KY "unnamed buffer"
1610 .IP "unnamed buffer"
1611 The unnamed buffer is a text storage area which is used by commands
1612 that use or operate on a buffer when no buffer is specified by the user.
1613 If the command stores text into a buffer,
1614 the text is stored into the unnamed buffer even if a buffer is also
1615 specified by the user.
1616 It is not possible to append text to the unnamed buffer.
1617 If text is appended to a named buffer,
1618 the named buffer contains both the old and new text,
1619 while the unnamed buffer contains only the new text.
1620 There is no way to explicitly reference the unnamed buffer.
1621 .sp
1622 Historically, the contents of the unnamed buffer were discarded by many
1623 different commands, even ones that didn't store text into it.
1624 .EV Nex nvi
1625 never discards the contents of the unnamed buffer until new text
1626 replaces them.
1627 .KY whitespace
1628 .IP whitespace
1629 The characters <tab> and <space>.
1630 .KY "<carriage-return>"
1631 .IP "<carriage-return>"
1632 The character represented by an ASCII
1633 .LI <control-M> .
1634 This character is almost always treated identically to a
1635 .LI <newline>
1636 character, but differs in that it can be escaped into the file text or
1637 into a command.
1638 .KY <newline>
1639 .IP <newline>
1640 The character represented by an ASCII
1641 .LI <control-J> .
1642 This character is almost always treated identically to a
1643 .LI <control-M>
1644 character, but differs in that it cannot be escaped into the file text or
1645 into a command.
1646 .oh 'Vi/Ex Reference (Vi Commands)''USD:13-%'
1647 .eh 'USD:13-%''Vi/Ex Reference (Vi Commands)'
1648 .so vi.cmd.roff
1649 .oh 'Vi/Ex Reference''USD:13-%'
1650 .eh 'USD:13-%''Vi/Ex Reference'
1651 .SH 1 "Ex Addressing"
1652 .pp
1653 Addressing in
1654 .CO ex
1655 (and when
1656 .CO ex
1657 commands are executed from
1658 .CO vi )
1659 relates to the current line.
1660 In general, the current line is the last line affected by a command.
1661 The exact effect on the current line is discussed under the description
1662 of each command.
1663 When the file contains no lines, the current line is zero.
1664 .pp
1665 Addresses are constructed by one or more of the following methods:
1666 .np
1667 The address
1668 .QT \&.
1669 refers to the current line.
1670 .np
1671 The address
1672 .QT $
1673 refers to the last line of the file.
1674 .np
1675 The address
1676 .QT N ,
1677 where
1678 .LI N
1679 is a positive number, refers to the N-th line of the file.
1680 .np
1681 The address
1682 .QT '<character>
1683 or
1684 .QT `<character>
1685 refers to the line marked with the name
1686 .LI <character> .
1687 (See the
1688 .CO k
1689 or
1690 .CO m
1691 commands for more information on how to mark lines.)
1692 .np
1693 A regular expression (RE) enclosed by slashes
1694 .PQ /
1695 is an address,
1696 and it refers to the first line found by searching forward from the line
1697 .i after
1698 the current line toward the end of the file, and stopping at the
1699 first line containing a string matching the RE.
1700 (The trailing slash can be omitted at the end of the command line.)
1701 .sp
1702 If no RE is specified, i.e. the pattern is
1703 .QT // ,
1704 the last RE used in any command is used in the search.
1705 .sp
1706 If the
1707 .OP extended
1708 option is set, the RE is handled as an extended RE, not a basic RE.
1709 If the
1710 .OP wrapscan
1711 option is set, the search wraps around to the beginning of the file
1712 and continues up to and including the current line, so that the entire
1713 file is searched.
1714 .sp
1715 The form
1716 .QT \e/
1717 is accepted for historic reasons,
1718 and is identical to
1719 .QT // .
1720 .np
1721 An RE enclosed in question marks
1722 .PQ ?
1723 addresses the first line found by searching backward from the line
1724 .i preceding
1725 the current line, toward the beginning of the file and stopping at the
1726 first line containing a string matching the RE.
1727 (The trailing question mark can be omitted at the end of a command line.)
1728 .sp
1729 If no RE is specified, i.e. the pattern is
1730 .QT ?? ,
1731 the last RE used in any command is used in the search.
1732 .sp
1733 If the
1734 .OP extended
1735 option is set, the RE is handled as an extended RE, not a basic RE.
1736 If the
1737 .OP wrapscan
1738 option is set, the search  wraps around from the beginning of the file to
1739 the end of the file and continues up to and including the current line,
1740 so that the entire file is searched.
1741 .sp
1742 The form
1743 .QT \e?
1744 is accepted for historic reasons, and is identical to
1745 .QT ?? .
1746 .np
1747 An address followed by a plus sign
1748 .PQ +
1749 or a minus sign
1750 .PQ -
1751 followed by a number is an offset address and refers to the address
1752 plus (or minus) the indicated number of lines.
1753 If the address is omitted, the addition or subtraction is done with
1754 respect to the current line.
1755 .np
1756 An address of
1757 .QT +
1758 or
1759 .QT \-
1760 followed by a number is an offset from the current line.
1761 For example,
1762 .QT \-5
1763 is the same as
1764 .QT \&.\-5 .
1765 .np
1766 An address ending with
1767 .QT +
1768 or
1769 .QT -
1770 has 1 added to or subtracted from the address, respectively.
1771 As a consequence of this rule and of the previous rule, the address
1772 .QT \-
1773 refers to the line preceding the current line.
1774 Moreover, trailing
1775 .QT +
1776 and
1777 .QT \-
1778 characters have a cumulative effect.
1779 For example,
1780 .QT ++\-++
1781 refers to the current line plus 3.
1782 .np
1783 A percent sign
1784 .PQ %
1785 is equivalent to the address range
1786 .QT 1,$ .
1787 .pp
1788 .CO Ex
1789 commands require zero, one, or two addresses.
1790 It is an error to specify an address to a command which requires zero
1791 addresses.
1792 .pp
1793 If the user provides more than the expected number of addresses to any
1794 .CO ex
1795 command, the first addresses specified are discarded.
1796 For example,
1797 .QT 1,2,3,5 print
1798 prints lines 3 through 5, because the
1799 .CO print
1800 command only takes two addresses.
1801 .pp
1802 The addresses in a range are separated from each other by a comma
1803 .PQ ,
1804 or a semicolon
1805 .PQ ; .
1806 In the latter case, the current line
1807 .PQ \&.
1808 is set to the first address, and only then is the second address calculated.
1809 This feature can be used to determine the starting line for forward and
1810 backward searches (see rules (5) and (6) above).
1811 The second address of any two-address sequence corresponds to a line that
1812 follows, in the file, the line corresponding to the first address.
1813 The first address must be less than or equal to the second address.
1814 The first address must be greater than or equal to the first line of the
1815 file, and the last address must be less than or equal to the last line
1816 of the file.
1817 .oh 'Vi/Ex Reference (Ex Commands)''USD:13-%'
1818 .eh 'USD:13-%''Vi/Ex Reference (Ex Commands)'
1819 .so ex.cmd.roff
1820 .oh 'Vi/Ex Reference (Options)''USD:13-%'
1821 .eh 'USD:13-%''Vi/Ex Reference (Options)'
1822 .so set.opt.roff
1823 .oh 'Vi/Ex Reference''USD:13-%'
1824 .eh 'USD:13-%''Vi/Ex Reference'
1825 .bp
1826 .SH 1 Index
1827 .lp
1828 .2c +0.5i 3
1829 .ta \n($luR
1830 .nf
1831 .so index.so
1832 .fi
1833 .\" Force the TOC to an odd page, in case it's a duplex printer.
1834 .if o .bp
1835 .bp 3
1836 .1c
1837 .ce 1
1838 \fB\s+2Table of Contents\s0\fP
1839 .sp
1840 .xp