2 .\" The Regents of the University of California. All rights reserved.
3 .\" Copyright (c) 1994, 1995, 1996
4 .\" Keith Bostic. All rights reserved.
6 .\" This document may not be republished without written permission from
9 .\" See the LICENSE file for redistribution information.
11 .\" $Id: vi.ref,v 8.90 2001/01/28 13:48:00 skimo Exp $ (Berkeley) $Date: 2001/01/28 13:48:00 $
19 Vi/Ex Reference Manual
25 Computer Science Division
26 Department of Electrical Engineering and Computer Science
27 University of California, Berkeley
28 Berkeley, California 94720
38 This document is the reference guide for the 4.4BSD
41 which are implementations of the historic Berkeley
47 Copyright (c) 1991, 1992, 1993, 1994
49 The Regents of the University of California. All Rights Reserved.
51 Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996
53 Keith Bostic. All Rights Reserved.
61 Bruce Englar encouraged the early development of the historic
64 Peter Kessler helped bring sanity to version 2's command layout.
65 Bill Joy wrote versions 1 and 2.0 through 2.7,
66 and created the framework that users see in the present editor.
67 Mark Horton added macros and other features and made
69 work on a large number of terminals and Unix systems.
72 is originally derived from software contributed to the University of
73 California, Berkeley by Steve Kirkendall, the author of the
78 IEEE Standard Portable Operating System Interface for Computer
79 Environments (POSIX) 1003.2 style Regular Expression support was
80 done by Henry Spencer.
82 The curses library was originally done by Ken Arnold.
83 Scrolling and reworking for
85 was done by Elan Amir.
87 George Neville-Neil added the Tcl interpreter,
88 and Sven Verdoolaege added the Perl interpreter.
90 Rob Mayoff added Cscope support.
92 The Institute of Electrical and Electronics Engineers has
93 given us permission to reprint portions of their documentation.
94 Portions of this document are reprinted and reproduced from
95 IEEE Std 1003.2-1992, IEEE Standard Portable Operating
96 System Interface for Computer Environments (POSIX),
97 copyright 1992 by the Institute of Electrical and Electronics
100 The financial support of UUNET Communications Services is gratefully
104 .oh 'Vi/Ex Reference''USD:13-%'
105 .eh 'USD:13-%''Vi/Ex Reference'
110 is a screen oriented text editor.
112 is a line-oriented text editor.
116 are different interfaces to the same program,
117 and it is possible to switch back and forth during an edit session.
119 is the equivalent of using the
121 (read-only) option of
124 This reference manual is the one provided with the
130 are intended as bug-for-bug compatible replacements for the original
131 Fourth Berkeley Software Distribution (4BSD)
134 This reference manual is accompanied by a traditional-style manual page.
135 That manual page describes the functionality found in
137 in far less detail than the description here.
138 In addition, it describes the system interface to
140 e.g. command line options, session recovery, signals,
141 environmental variables, and similar things.
143 This reference is intended for users already familiar with
145 Anyone else should almost certainly read a good tutorial on the
147 If you are in an unfamiliar environment,
148 and you absolutely have to get work done immediately,
149 see the section entitled
152 It is probably enough to get you started.
154 There are a few features in
156 that are not found in historic versions of
158 Some of the more interesting of those features are briefly described
159 in the next section, entitled
160 .QB "Additional Features" .
161 For the rest of this document,
163 is used only when it is necessary to distinguish it from the historic
167 Future versions of this software will be periodically made available
168 by anonymous ftp, and can be retrieved from
169 .LI ftp.cs.berkeley.edu ,
172 .SH 1 "Additional Features in Nex/Nvi"
174 There are a few features in
176 that are not found in historic versions of
178 Some of the more interesting of these are as follows:
179 .IP "8-bit clean data, large lines, files"
181 will edit any format file.
182 Line lengths are limited by available memory,
183 and file sizes are limited by available disk space.
186 text input mode command
188 can insert any possible character value into the text.
189 .IP "Background and foreground screens"
192 command backgrounds the current screen, and the
194 command foregrounds backgrounded screens.
197 command can be used to list the background screens.
198 .IP "Command Editing"
199 You can enter a normal editing window on the collected commands that
200 you've entered on the
203 and then modify and/or execute the commands.
206 edit option for more information.
210 command can be used to display the current buffers, the backgrounded
211 screens, and the tags stack.
212 .IP "Extended Regular Expressions"
215 option causes Regular Expressions to be interpreted as as Extended
216 Regular Expressions, (i.e. \fIegrep\fP(1) style Regular Expressions).
217 .IP "File Name Completion"
218 It is possible to do file name completion and file name displays when
219 entering commands on the
224 option for more information.
226 Changes made during an edit session may be rolled backward and forward.
229 command immediately after a
231 command continues either forward or backward depending on whether the
233 command was an undo or a redo.
234 .IP "Left-right scrolling"
239 to do left-right screen scrolling, instead of the traditional
242 .IP "Message Catalogs"
243 It is possible to display informational and error messages in different
244 languages by providing a catalog of messages.
249 for more information.
250 .IP "Incrementing numbers"
253 command increments or decrements the number referenced by the cursor.
257 command edits the previous file from the argument list.
258 .IP "Scripting languages"
264 commands execute Perl and Tcl/Tk commands, respectively,
265 on lines from the edit buffer.
267 .QB "Scripting Languages"
268 section and the specific commands for more information.
269 .\".IP "Shell screens"
271 .\".CO ":sc[ript] [file ...]"
272 .\"command runs a shell in the screen.
273 .\"Editing is unchanged, with the exception that a \fC<carriage-return>\fP
274 .\"enters the current line (stripped of any prompt) as input to the
287 mode) commands divide the screen into multiple editing regions and
288 then perform their normal function in a new screen area.
291 command rotates between the foreground screens.
294 command can be used to grow or shrink a particular screen.
296 Tags are now maintained in a stack.
299 command returns to the previous tag location.
302 command returns to the most recent tag location by default, or,
303 optionally to a specific tag number in the tag stack,
304 or the most recent tag from a specified file.
307 command can be used to list the tags stack.
310 command returns to the top of the tag stack.
311 .IP "Usage information"
316 commands provide usage information for all of the
320 commands by default, or, optionally, for a specific command or key.
324 command searches for the word referenced by the cursor.
325 .SH 1 "Startup Information"
328 interprets one of two possible environmental variables and reads up to
329 three of five possible files during startup.
330 The variables and files are expected to contain
335 In addition, they are interpreted
337 the file to be edited is read, and therefore many
339 commands may not be used.
340 Generally, any command that requires output to the screen or that
341 needs a file upon which to operate, will cause an error if included
342 in a startup file or environmental variable.
346 command set supported by
348 is a superset of the command set supported by historical implementations of
351 can use the startup files created for the historical implementations,
352 but the converse may not be true.
356 (the historic \- option)
357 is specified, or if standard input is redirected from a file,
358 all environmental variables and startup files are ignored.
360 Otherwise, startup files and environmental variables are handled
361 in the following order:
366 as long as it is owned by root or the effective user ID of the user.
368 The environmental variable
374 is not set) is interpreted.
382 environmental variable is set, the file
388 does not exist) is read,
389 as long as the effective user ID of the user is root or is the same as
390 the owner of the file.
392 When the $HOME directory is being used for both
394 and an historic implementation of
396 a possible solution is to put
398 specific commands in the
401 .CO ":source $HOME/.exrc"
402 command to read in the commands common to both implementations.
406 option was turned on by one of the previous startup information
413 does not exist) is read, as long as the effective user ID of the user
414 is the same as the owner of the file.
416 No startup file is read if it is writable by anyone other than its owner.
418 It is not an error for any of the startup environmental variables or files
421 Once all environmental variables are interpreted,
422 and all startup files are read,
423 the first file to be edited is read in (or a temporary file is created).
424 Then, any commands specified using the
426 option are executed, in the context of that file.
429 There is no recovery program for
434 Recovery files are created readable and writable by the owner only.
435 Users may recover any file which they can read,
436 and the superuser may recover any edit session.
438 Edit sessions are backed by files in the directory named by the
440 option (the directory
441 .LI /var/tmp/vi.recover
442 by default), and are named
446 is a number related to the process ID.
447 When a file is first modified,
448 a second recovery file containing an email message for the user is created,
453 is associated with the process ID.
454 Both files are removed at the end of a normal edit session,
455 but will remain if the edit session is abnormally terminated
463 option may be set in either the user's or system's startup information,
464 changing the recovery directory.
465 (Note, however, that if a memory based file system is used as the backup
466 directory, each system reboot will delete all of the recovery files!
467 The same caution applies to directories such as
469 which are cleared of their contents by a system reboot, or
471 which is periodically cleared of old files on many systems.)
473 The recovery directory should be owned by root, or at least by a pseudo-user.
474 In addition, if directory
476 semantics are available, the directory should have the sticky-bit
477 set so that files may only be removed by their owners.
478 The recovery directory must be read, write, and executable by any user,
481 If the recovery directory does not exist,
483 will attempt to create it.
484 This can result in the recovery directory being owned by a normal user,
485 which means that that user will be able to remove other user's recovery
487 This is annoying, but is not a security issue as the user cannot
488 otherwise access or modify the files.
490 The recovery file has all of the necessary information in it to enable the
491 user to recover the edit session.
492 In addition, it has all of the necessary email headers for
494 When the system is rebooted, all of the files in
495 .LI /var/tmp/vi.recover
498 should be sent to their owners, by email, using the
502 (or a similar mechanism in other mailers).
505 receives a hangup (SIGHUP) signal, or the user executes the
510 will automatically email the recovery information to the user.
512 If your system does not have the
514 utility (or a mailer program which supports its interface)
516 .LI nvi/common/recover.c
517 will have to be modified to use your local mail delivery programs.
520 is changed to use another mailer,
521 it is important to remember that the owner of the file given to
524 user, so nothing in the file should be trusted as it may have been
525 modified in an effort to compromise the system.
527 Finally, the owner execute bit is set on backup files when they are
528 created, and unset when they are first modified, e.g. backup files
529 that have no associated email recovery file will have this bit set.
530 (There is also a small window where empty files can be created and
531 not yet have this bit set.
532 This is due to the method in which the files are created.)
533 Such files should be deleted when the system reboots.
535 A simple way to do this cleanup is to run the Bourne shell script
539 (or other system startup) file.
540 The script should work with the historic Bourne shell,
541 a POSIX 1003.2 shell or the Korn shell.
544 script is installed as part of the
546 installation process.
548 Consult the manual page for details on recovering preserved or
549 aborted editing sessions.
550 .SH 1 "Sizing the Screen"
552 The size of the screen can be set in a number of ways.
554 takes the following steps until values are obtained for both the
555 number of rows and number of columns in the screen.
557 If the environmental variable
560 it is used to specify the number of rows in the screen.
562 If the environmental variable
565 it is used to specify the number of columns in the screen.
569 is attempted on the standard error file descriptor.
571 The termcap entry (or terminfo entry on System V machines)
578 The number of rows is set to 24, and the number of columns is set to 80.
580 If a window change size signal (SIGWINCH) is received,
581 the new window size is retrieved using the TIOCGWINSZ
583 call, and all other information is ignored.
584 .SH 1 "Character Display"
590 printable characters as defined by
592 are displayed using the local character set.
594 Non-printable characters, for which
596 returns true, and which are less than octal \e040,
597 are displayed as the string
601 is the character that is the original character's value offset from the
604 For example, the octal character \e001 is displayed as
608 returns true for the octal character \e177,
609 it is displayed as the string
611 All other characters are displayed as either hexadecimal values,
613 .QT "0x<high-halfbyte> ... 0x<low-halfbyte>" ,
614 or as octal values, in the form
615 .QT "\e<high-one-or-two-bits> ... \e<low-three-bits>" .
616 The display of unknown characters is based on the value of the
622 command mode, the cursor is always positioned on the last column of
623 characters which take up more than one column on the screen.
626 text input mode, the cursor is positioned on the first column of
627 characters which take up more than one column on the screen.
628 .SH 1 "Multiple Screens"
631 supports multiple screens by dividing the window into regions.
632 It also supports stacks of screens by permitting the user to change
633 the set of screens that are currently displayed.
647 commands divide the current screen into two regions of approximately
648 equal size and then perform their usual action in a new screen area.
649 If the cursor is in the lower half of the screen, the screen will split
650 up, i.e. the new screen will be above the old one.
651 If the cursor is in the upper half of the screen, the new screen will be
654 When more than one screen is editing a file, changes in any screen are
655 reflected in all other screens editing the same file.
656 Exiting a screen without saving any changes (or explicitly discarding
657 them) is permitted until the last screen editing the file is exited,
658 at which time the changes must be saved or discarded.
662 command permits resizing of individual screens.
663 Screens may be grown, shrunk or set to an absolute number of rows.
667 command is used to switch between screens.
670 moves to the next lower screen in the window, or to the first screen
671 in the window if there are no lower screens.
678 The screen disappears from the window,
679 and the rows it occupied are taken over by a neighboring screen.
680 It is an error to attempt to background the only screen in the window.
683 .CO "display screens"
684 command displays the names of the files associated with the current
685 backgrounded screens in the window.
689 command moves the specified screen from the list of backgrounded screens
691 If no file argument is specified, the first screen on the list is
694 foregrounding consists of backgrounding the current screen,
695 and replacing its space in the window with the foregrounded screen.
697 Capitalizing the first letter of the command, i.e.
699 will foreground the backgrounded screen in a new screen instead of
700 swapping it with the current screen.
702 If the last foregrounded screen in the window is exited,
703 and there are backgrounded screens,
704 the first screen on the list of backgrounded screens takes over the window.
705 .SH 1 "Tags, Tag Stacks, and Cscope"
708 supports the historic
716 These commands change the current file context to a new location,
717 based on information found in the
720 If you are unfamiliar with these commands,
721 you should review their description in the
725 commands section of this manual.
726 For additional information on tags files,
727 see the discussion of the
729 edit option and the system
735 supports the notion of
742 command returns the user to the previous context, i.e.,
743 the last place from which a
748 These three commands provide the basic functionality which allows you
751 to review source code in a structured manner.
754 also provides two other basic
756 commands for tag support:
762 command is identical to the
765 with the additional functionality that you may specify that modifications
766 to the current file are to be discarded.
767 This cannot be done using the
772 command discards all of the contexts that have been pushed onto the tag
773 stack, returning to the context from which the first
781 tags file format supports only a single location per tag,
782 normally the function declaration or structure or string definition.
783 More sophisticated source code tools often provide multiple locations
785 a list of the places from which a function is called or a string
787 An example of this functionality is the System V source code tool,
791 creates a database of information on source code files,
792 and supports a query language for that information as described in the
796 contains an interface to the
798 query language which permits you to query
800 and then sequentially step through the locations in the sources files which
805 commands which support this ability to step through multiple locations.
814 command moves to the next location for the current tag.
817 command moves to the previous location for the current tag.
822 command discussion in the
824 commands section of this manual for more information.)
825 At any time during this sequential walk,
831 commands to move to a new tag context, and then use the
835 commands to return and continue stepping through the locations for this
837 This is similar to the previous model of a simple tag stack,
838 except that each entry in the tag stack may have more than one file context
841 Although there is no widely distributed version of
843 that creates tags files with multiple locations per tag,
845 has been written to understand the obvious extension to the historic
846 tags file format, i.e., more than a single line in the tags file with
847 the same initial tag name.
848 If you wish to extend your
850 implementation or other tool with which you build tags files,
851 this extension should be simple and will require no changes to
858 interface is based on the new
862 which has five subcommands:
871 itself has eight subcommands:
882 .IP "cs[cope] a[dd] file"
885 command attaches to the specified
888 The file name is expanded using the standard filename expansions.
891 is a directory, the file
893 in that directory is used as the database.
897 attaches to a new database,
900 queries will be asked of that database.
901 The result of any single query is the collection of response to the query
902 from all of the attached databases.
906 environmental variable is set when
909 it is expected to be a <colon> or <blank>-separated list of
911 databases or directories containing
913 databases, to which the user wishes to attach.
914 .IP ":cs[cope] f[ind] c|d|e|f|g|i|s|t buffer|pattern"
925 databases for the pattern.
926 If the pattern is a double-quote character followed by a valid buffer
928 .LI """<character>" ),
929 then the contents of the named buffer are used as the pattern.
930 Otherwise, the pattern is a Regular Expression.
934 command pushes the current location onto the tags stack,
935 and switches to the first location resulting from the query,
936 if the query returned at least one result.
938 File names returned by the
940 query, if not absolute paths, are searched for relative to the directory
944 In addition, if the file
946 appears in the same directory as the
949 it is expected to contain a colon-separated list of directory names
950 where files referenced by its associated
952 database may be found.
956 subcommand is one of the following:
959 Find callers of the name.
961 Find all function calls made from name.
965 Find files with name as substring.
967 Find definition of name.
969 Find files #including name.
971 Find all uses of name.
973 Find assignments to name.
975 .IP ":cs[cope] h[elp] [command]"
979 or optionally list usage help for any single
982 .IP ":display c[onnections]"
987 is currently connected.
988 .IP ":cs[cope] k[ill] #"
989 Disconnect from a specific
992 The connection number is the one displayed by the
994 .CO "display connections"
996 .IP ":cs[cope] r[eset]"
997 Disconnect from all attached
1001 Cscope is not freely redistributable software,
1002 but is fairly inexpensive and easily available.
1003 To purchase a copy of
1005 see http://www.att.com/ssg/products/toolchest.html.
1006 .SH 1 "Regular Expressions and Replacement Strings"
1008 Regular expressions are used in line addresses,
1009 as the first part of the
1015 commands, and in search patterns.
1017 The regular expressions supported by
1019 are, by default, the Basic Regular Expressions (BRE's) described in the
1020 IEEE POSIX Standard 1003.2.
1023 option causes all regular expressions to be interpreted as the Extended
1024 Regular Expressions (ERE's) described by the same standard.
1027 for more information.)
1028 Generally speaking, BRE's are the Regular Expressions found in
1032 and ERE's are the Regular Expressions found in
1035 The following is not intended to provide a description of Regular
1037 The information here only describes strings and characters which
1038 have special meanings in the
1041 or options which change the meanings of characters that normally
1042 have special meanings in RE's.
1048 is equivalent to the last RE used.
1052 matches the beginning of a word.
1056 matches the end of a word.
1060 matches the replacement part of the last
1068 set, the only characters with special meanings are a
1070 character at the beginning of an RE, a
1072 character at the end of an RE, and the escaping character
1080 are treated as ordinary characters unless preceded by a
1084 they regain their special meaning.
1086 Replacement strings are the second part of a
1098 set) in the replacement string stands for the text matched by the RE
1099 that is being replaced.
1108 set) stands for the replacement part of the previous
1111 It is only valid after a
1113 command has been performed.
1119 is an integer value from 1 to 9, stands for the text matched by
1120 the portion of the RE enclosed in the
1122 set of escaped parentheses, e.g.
1127 .QT "s/abc\e(.*\e)def/\e1/"
1132 from the matched pattern.
1140 can be used to modify the case of elements in the replacement string.
1143 causes the next character to be converted to lowercase;
1146 behaves similarly, but converts to uppercase
1155 causes characters up to the end of the string or the next occurrence
1160 to be converted to lowercase;
1163 behaves similarly, but converts to uppercase.
1165 If the entire replacement pattern is
1167 then the last replacement pattern is used again.
1173 into the replacement string will cause
1174 the matched line to be split into two lines at that point.
1178 .SH 1 "Scripting Languages"
1182 editor currently supports two scripting languages, Tcl/Tk and Perl.
1183 (Note that Perl4 isn't sufficient, and that the Perl5 used must be
1184 version 5.002 or later.
1187 section for more information.
1189 The scripting language interface is still being worked on,
1190 therefore the following information is probably incomplete,
1191 probably wrong in cases, and likely to change.
1196 source directories for more information.
1197 As a quick reference, the following function calls are provided for
1198 both the Perl and Tcl interfaces.
1199 The Perl interface uses a slightly different naming convention,
1200 e.g. ``viFindScreen'' is named ``VI::FindScreen''.
1201 .IP "viFindScreen file"
1203 .LI "screenId" associated with
1205 .IP "viAppendLine screenId lineNumber text"
1208 as a new line after line number
1212 .IP "viDelLine screenId lineNum"
1217 .IP "viGetLine screenId lineNumber"
1222 .IP "viInsertLine screenId lineNumber text"
1225 as a new line before line number
1229 .IP "viLastLine screenId"
1230 Return the line number of the last line in the screen
1232 .IP "viSetLine screenId lineNumber text"
1237 to match the specified
1239 .IP "viGetMark screenId mark"
1240 Return the current line and column for the specified
1244 .IP "viSetMark screenId mark line column"
1253 .IP "viGetCursor screenId"
1254 Return the current line and column for the cursor in the screen
1256 .IP "viSetCursor screenId line column"
1257 Set the cursor in the screen
1263 .IP "viMsg screenId text"
1264 Display the specified
1266 as a vi message in the screen
1268 .IP "viNewScreen screenId [file]"
1269 Create a new screen.
1270 .IP "viEndScreen screenId"
1273 .IP "viSwitchScreen screenId screenId"
1274 Switch from the screen
1278 .IP "viMapKey screenId key tclproc"
1283 to the Tcl procedure
1285 .IP "viUnmMapKey screenId key"
1290 .IP "viGetOpt screenId option"
1291 Return the value of the specified
1295 .IP "viSetOpt screenId command"
1296 Set one or more options in the screen
1298 .SH 1 "General Editor Description"
1305 the text of a file is read (or a temporary file is created),
1306 and then all editing changes happen within the context of the
1308 .i "No changes affect the actual file until the file is written out" ,
1309 either using a write command or another command which is affected by the
1313 All files are locked (using the
1317 interfaces) during the edit session,
1318 to avoid inadvertently making modifications to multiple copies of the file.
1319 If a lock cannot be obtained for a file because it is locked by another
1320 process, the edit session is read-only (as if the
1324 flag had been specified).
1325 If a lock cannot be obtained for other reasons, the edit session will
1326 continue, but the file status information
1329 command) will reflect this fact.
1335 are modeful editors, i.e. they have two modes,
1340 The former is intended to permit you to enter commands which modifies
1341 already existing text.
1342 The latter is intended to permit you to enter new text.
1345 first starts running, it is in command mode, and usually displays a prompt
1348 option for more information).
1349 The prompt is a single colon
1352 There are three commands that switch
1354 into text input mode:
1359 Once in input mode, entering a line containing only a single period
1361 ends text input mode and returns to command mode,
1362 where the prompt is redisplayed.
1366 first starts running, it is in command mode as well.
1367 There are eleven commands that switch
1369 into text input mode:
1382 Once in input mode, entering an
1384 character ends text input mode and returns to command mode.
1387 present three different interfaces to editing a file.
1389 presents a line oriented interface.
1391 presents a full screen display oriented interface,
1394 In addition, there is a third mode,
1396 which is line oriented,
1397 but supports cursor movement and editing within the displayed line,
1398 similarly to visual mode.
1399 Open mode is not yet implemented in
1402 The following words have special meanings in both the
1406 command descriptions:
1409 The interrupt character is used to interrupt the current operation.
1412 whatever character is set for the current terminal is used.
1413 .KY "<literal-next>"
1414 .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
1419 If the terminal is not set up to do XON/XOFF flow control,
1422 is used to mean literal next as well.
1423 .KY "current pathname"
1424 .IP "current pathname"
1425 The pathname of the file currently being edited by vi.
1426 When the percent character
1428 appears in a file name entered as part of an
1430 command argument, it is replaced by the current pathname.
1433 character can be escaped by preceding it with a backslash.)
1434 .KY "alternate pathname"
1435 .IP "alternate pathname"
1436 The name of the last file name mentioned in an
1439 the previous current pathname if the last file mentioned
1440 becomes the current file.
1441 When the hash mark character
1443 appears in a file name entered as part of an
1445 command argument, it is replaced by the alternate pathname.
1448 character can be escaped by preceding it with a backslash.)
1451 One of a number of named areas for saving copies of text.
1452 Commands that change or delete text can save the changed or deleted
1453 text into a specific buffer, for later use, if the command allows
1457 command cannot save the changed text in a named buffer).
1458 Buffers are named with a single character, preceded by a double quote,
1464 without the double quote, e.g.
1468 (The double quote isn't necessary for
1470 because buffers names are denoted by their position in the command line.)
1471 Historic implementations of
1475 to the alphanumeric characters;
1477 permits the use of any character without another meaning in the position
1478 where a buffer name is expected.
1480 Buffers named by uppercase characters are the same as buffers
1481 named by lowercase characters, e.g. the buffer named by the
1484 is the same as the buffer named by the character
1486 with the exception that, if the buffer contents are being changed (as
1487 with a text deletion or
1490 command), the text is
1492 to the buffer, instead of replacing the current contents.
1494 The buffers named by the numeric characters (in English,
1499 If a region of text including characters from more than one line,
1500 or a single line of text specified by using a line-oriented motion,
1501 is changed or deleted in the file using the
1506 commands, a copy of the text is placed into the numeric buffer
1508 regardless of the user specifying another buffer in which to save it.
1509 In addition, there are a few commands which, when used as a
1518 copy the specified region of text into the numeric buffers regardless
1519 of the region including characters from more than one line.
1532 Before this copy is done, the previous contents of buffer
1534 are moved into buffer
1540 The contents of buffer
1545 text may be explicitly stored into the numeric buffers.
1546 In this case, the buffer rotation described above occurs before the
1547 replacement of the buffer's contents.
1548 The numeric buffers are only available in
1553 and are not accessible by
1555 in any way, although changed and deleted text is still stored there
1562 command synopsis shows both a
1566 they may be presented in any order.
1568 Finally, all buffers are either
1575 commands which store text into buffers are line oriented.
1578 commands which store text into buffers are line oriented,
1579 and some are character oriented; the description for each applicable
1581 command notes whether text copied into buffers using the command
1582 is line or character oriented.
1586 .CO "display buffers"
1587 displays the current orientation for each buffer.
1588 Generally, the only importance attached to this orientation is that
1589 if the buffer is subsequently inserted into the text, line oriented
1590 buffers create new lines for each of the lines they contain, and
1591 character oriented buffers create new lines for any lines
1593 than the first and last lines they contain.
1594 The first and last lines are inserted into the text at the current
1595 cursor position, becoming part of the current line.
1596 If there is more than one line in the buffer, however, the current
1597 line itself will be split.
1598 .KY "unnamed buffer"
1599 .IP "unnamed buffer"
1600 The unnamed buffer is a text storage area which is used by commands
1601 that use or operate on a buffer when no buffer is specified by the user.
1602 If the command stores text into a buffer,
1603 the text is stored into the unnamed buffer even if a buffer is also
1604 specified by the user.
1605 It is not possible to append text to the unnamed buffer.
1606 If text is appended to a named buffer,
1607 the named buffer contains both the old and new text,
1608 while the unnamed buffer contains only the new text.
1609 There is no way to explicitly reference the unnamed buffer.
1611 Historically, the contents of the unnamed buffer were discarded by many
1612 different commands, even ones that didn't store text into it.
1614 never discards the contents of the unnamed buffer until new text
1618 The characters <tab> and <space>.
1619 .KY "<carriage-return>"
1620 .IP "<carriage-return>"
1621 The character represented by an ASCII
1623 This character is almost always treated identically to a
1625 character, but differs in that it can be escaped into the file text or
1629 The character represented by an ASCII
1631 This character is almost always treated identically to a
1633 character, but differs in that it cannot be escaped into the file text or
1635 .oh 'Vi/Ex Reference (Vi Commands)''USD:13-%'
1636 .eh 'USD:13-%''Vi/Ex Reference (Vi Commands)'
1638 .oh 'Vi/Ex Reference''USD:13-%'
1639 .eh 'USD:13-%''Vi/Ex Reference'
1640 .SH 1 "Ex Addressing"
1646 commands are executed from
1648 relates to the current line.
1649 In general, the current line is the last line affected by a command.
1650 The exact effect on the current line is discussed under the description
1652 When the file contains no lines, the current line is zero.
1654 Addresses are constructed by one or more of the following methods:
1658 refers to the current line.
1662 refers to the last line of the file.
1668 is a positive number, refers to the N-th line of the file.
1674 refers to the line marked with the name
1680 commands for more information on how to mark lines.)
1682 A regular expression (RE) enclosed by slashes
1685 and it refers to the first line found by searching forward from the line
1687 the current line toward the end of the file, and stopping at the
1688 first line containing a string matching the RE.
1689 (The trailing slash can be omitted at the end of the command line.)
1691 If no RE is specified, i.e. the pattern is
1693 the last RE used in any command is used in the search.
1697 option is set, the RE is handled as an extended RE, not a basic RE.
1700 option is set, the search wraps around to the beginning of the file
1701 and continues up to and including the current line, so that the entire
1706 is accepted for historic reasons,
1710 An RE enclosed in question marks
1712 addresses the first line found by searching backward from the line
1714 the current line, toward the beginning of the file and stopping at the
1715 first line containing a string matching the RE.
1716 (The trailing question mark can be omitted at the end of a command line.)
1718 If no RE is specified, i.e. the pattern is
1720 the last RE used in any command is used in the search.
1724 option is set, the RE is handled as an extended RE, not a basic RE.
1727 option is set, the search wraps around from the beginning of the file to
1728 the end of the file and continues up to and including the current line,
1729 so that the entire file is searched.
1733 is accepted for historic reasons, and is identical to
1736 An address followed by a plus sign
1740 followed by a number is an offset address and refers to the address
1741 plus (or minus) the indicated number of lines.
1742 If the address is omitted, the addition or subtraction is done with
1743 respect to the current line.
1749 followed by a number is an offset from the current line.
1755 An address ending with
1759 has 1 added to or subtracted from the address, respectively.
1760 As a consequence of this rule and of the previous rule, the address
1762 refers to the line preceding the current line.
1767 characters have a cumulative effect.
1770 refers to the current line plus 3.
1774 is equivalent to the address range
1778 commands require zero, one, or two addresses.
1779 It is an error to specify an address to a command which requires zero
1782 If the user provides more than the expected number of addresses to any
1784 command, the first addresses specified are discarded.
1787 prints lines 3 through 5, because the
1789 command only takes two addresses.
1791 The addresses in a range are separated from each other by a comma
1795 In the latter case, the current line
1797 is set to the first address, and only then is the second address calculated.
1798 This feature can be used to determine the starting line for forward and
1799 backward searches (see rules (5) and (6) above).
1800 The second address of any two-address sequence corresponds to a line that
1801 follows, in the file, the line corresponding to the first address.
1802 The first address must be less than or equal to the second address.
1803 The first address must be greater than or equal to the first line of the
1804 file, and the last address must be less than or equal to the last line
1806 .oh 'Vi/Ex Reference (Ex Commands)''USD:13-%'
1807 .eh 'USD:13-%''Vi/Ex Reference (Ex Commands)'
1809 .oh 'Vi/Ex Reference (Options)''USD:13-%'
1810 .eh 'USD:13-%''Vi/Ex Reference (Options)'
1812 .oh 'Vi/Ex Reference''USD:13-%'
1813 .eh 'USD:13-%''Vi/Ex Reference'
1823 .\" Force the TOC to an odd page, in case it's a duplex printer.
1828 \fB\s+2Table of Contents\s0\fP