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