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