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.1,v 8.53 2001/01/28 13:20:06 skimo Exp $ (Berkeley) $Date: 2001/01/28 13:20:06 $
16 ex, vi, view \- text editors
51 The vi program is freely redistributable. You are welcome to copy,
52 modify and share it with others under the conditions listed in the
53 LICENSE file. If any company (not individual!) finds vi sufficiently
54 useful that you would have purchased it, or if any company wishes to
55 redistribute it, contributions to the authors would be appreciated.
58 is a screen oriented text editor.
60 is a line-oriented text editor.
64 are different interfaces to the same program,
65 and it is possible to switch back and forth during an edit session.
67 is the equivalent of using the
72 This manual page is the one provided with the
78 are intended as bug-for-bug compatible replacements for the original
79 Fourth Berkeley Software Distribution (4BSD)
84 For the rest of this manual page,
86 is used only when it's necessary to distinguish it from the historic
90 This manual page is intended for users already familiar with
92 Anyone else should almost certainly read a good tutorial on the
93 editor before this manual page.
94 If you're in an unfamiliar environment, and you absolutely have to
95 get work done immediately, read the section after the options
96 description, entitled ``Fast Startup''.
97 It's probably enough to get you going.
99 The following options are available:
104 immediately after starting the edit session.
105 Particularly useful for initial positioning in the file, however
107 is not limited to positioning commands.
108 This is the POSIX 1003.2 interface for the historic ``+cmd'' syntax.
110 supports both the old and new syntax.
113 Start editing in ex mode, as if the command name were
117 Don't copy the entire file when first starting to edit.
118 (The default is to make a copy in case someone else modifies
119 the file during your edit session.)
122 Start editing with the lisp and showmatch options set.
125 Start editing in read-only mode, as if the command name was
132 Recover the specified files, or, if no files are specified,
133 list the files that could be recovered.
134 If no recoverable files by the specified name exist,
135 the file is edited as if the
137 option had not been specified.
142 edit option set, disallowing all access to external programs.
145 Enter batch mode; applicable only to
148 Batch mode is useful when running
151 Prompts, informative messages and other user oriented message
153 and no startup files or environmental variables are read.
154 This is the POSIX 1003.2 interface for the historic ``\-'' argument.
156 supports both the old and new syntax.
159 Start editing at the specified tag.
164 Set the initial window size to the specified number of lines.
167 Start editing in vi mode, as if the command name was
174 is read from the standard input.
177 interface, it is an error if standard input is not a terminal.
180 interface, if standard input is not a terminal,
182 will read commands from it regardless, however, the session will be a
183 batch mode session, exactly as if the
185 option had been specified.
188 exits 0 on success, and greater than 0 if an error occurs.
190 This section will tell you the minimum amount that you need to
191 do simple editing tasks using
193 If you've never used any screen editor before, you're likely to have
194 problems even with this simple introduction.
195 In that case you should find someone that already knows
197 and have them walk you through this section.
201 This means that it takes up almost the entire screen, displaying part
202 of the file on each screen line, except for the last line of the screen.
203 The last line of the screen is used for you to give commands to
207 to give information to you.
209 The other fact that you need to understand is that
211 is a modeful editor, i.e. you are either entering text or you
212 are executing commands, and you have to be in the right mode
213 to do one or the other.
214 You will be in command mode when you first start editing a file.
215 There are commands that switch you into input mode.
216 There is only one key that takes you out of input mode,
217 and that is the <escape> key.
218 (Key names are written using less-than and greater-than signs, e.g.
219 <escape> means the ``escape'' key, usually labeled ``esc'' on your
220 terminal's keyboard.)
221 If you're ever confused as to which mode you're in,
222 keep entering the <escape> key until
227 will beep at you if you try and do something that's not allowed.
228 It will also display error messages.)
230 To start editing a file, enter the command ``vi file_name<carriage-return>''.
231 The command you should enter as soon as you start editing is
232 ``:set verbose showmode<carriage-return>''.
233 This will make the editor give you verbose error messages and display
234 the current mode at the bottom of the screen.
236 The commands to move around the file are:
239 Move the cursor left one character.
242 Move the cursor down one line.
245 Move the cursor up one line.
248 Move the cursor right one character.
251 The cursor arrow keys should work, too.
253 .B /text<carriage-return>
254 Search for the string ``text'' in the file,
255 and move the cursor to its first character.
257 The commands to enter new text are:
270 Open a new line below the line the cursor is on, and start
274 Open a new line above the line the cursor is on, and start
278 Once you've entered input mode using the one of the
286 to quit entering text and return to command mode.
288 The commands to copy text are:
291 Copy the line the cursor is on.
294 Append the copied line after the line the cursor is on.
296 The commands to delete text are:
299 Delete the line the cursor is on.
302 Delete the character the cursor is on.
304 The commands to write the file are:
306 .B :w<carriage-return>
307 Write the file back to the file with the name that you originally used
308 as an argument on the
312 .B ":w file_name<carriage-return>"
313 Write the file back to the file with the name ``file_name''.
315 The commands to quit editing and exit the editor are:
317 .B :q<carriage-return>
318 Quit editing and leave vi (if you've modified the file, but not
321 will refuse to quit).
323 .B :q!<carriage-return>
324 Quit, discarding any modifications that you may have made.
327 Unusual characters can take up more than one column on the screen,
328 and long lines can take up more than a single screen line.
329 The above commands work on ``physical'' characters and lines,
330 i.e. they affect the entire line no matter how many screen lines it
331 takes up and the entire character no matter how many screen columns
334 The following section describes the commands available in the command
338 In each entry below, the tag line is a usage synopsis for the command
342 .B "[count] <control-A>"
345 times for the current word.
347 .B "[count] <control-B>"
352 .B "[count] <control-D>"
357 .B "[count] <control-E>"
360 lines, leaving the current line and column as is, if possible.
362 .B "[count] <control-F>"
368 Display the file information.
375 characters in the current line.
377 .B "[count] <control-J>"
379 .B "[count] <control-N>"
384 lines without changing the current column.
391 .B "[count] <control-M>"
396 lines to the first nonblank character of that line.
398 .B "[count] <control-P>"
403 lines, without changing the current column.
406 Return to the most recent tag context.
414 Switch to the next lower screen in the window, or, to the first
415 screen if there are no lower screens in the window.
420 lines, leaving the current line and column as is, if possible.
423 Suspend the current editor session.
428 commands or cancel partial commands.
431 Push a tag reference onto the tag stack.
434 Switch to the most recently edited file.
439 Move the cursor forward
441 characters without changing the current line.
443 .B "[count] ! motion shell-argument(s)"
444 Replace text with results from a shell command.
447 Increment or decrement the cursor number.
450 Move the cursor to the end of a line.
453 Move to the matching character.
456 Repeat the previous substitution command on the current line.
461 Return to a context marked by the character
475 Reverse find character
480 Move to first nonblank of the previous line,
487 command that modified text.
489 .B "/RE<carriage-return>"
491 .B "/RE/ [offset]<carriage-return>"
493 .B "?RE<carriage-return>"
495 .B "?RE? [offset]<carriage-return>"
500 Search forward or backward for a regular expression.
503 Move to the first character in the current line.
506 Execute an ex command.
509 Repeat the last character find
513 .B "[count] < motion"
515 .B "[count] > motion"
516 Shift lines left or right.
519 Execute a named buffer.
522 Enter input mode, appending the text after the end of the line.
529 .B "[buffer] [count] C"
530 Change text from the current position to the end-of-line.
533 Delete text from the current position to the end-of-line.
540 .B "[count] F <character>"
543 times backward through the current line for
549 or the last line of the file if
554 Move to the screen line
556 lines below the top of the screen.
559 Enter input mode, inserting the text at the beginning of the line.
565 Move to the screen line
567 lines above the bottom of the screen.
570 Move to the screen line in the middle of the screen.
573 Enter input mode, appending text in a new line above the current line.
576 Insert text from a buffer.
581 (or visual) mode and switch to
586 Enter input mode, replacing the characters in the current line.
588 .B "[buffer] [count] S"
593 .B "[count] T <character>"
597 through the current line for the character
603 Restore the current line to its state before the cursor last
611 .B "[buffer] [count] X"
614 characters before the cursor.
616 .B "[buffer] [count] Y"
619 lines into the specified buffer.
622 Write the file and exit
636 Move to first nonblank character on the current line.
641 lines, to the first nonblank character.
644 Enter input mode, appending the text after the cursor.
651 .B "[buffer] [count] c motion"
652 Change a region of text.
654 .B "[buffer] [count] d motion"
655 Delete a region of text.
662 .B "[count] f<character>"
665 times, through the rest of the current line for
669 Enter input mode, inserting the text before the cursor.
672 Save the current context (line and column) as
676 Enter input mode, appending text in a new line under the current line.
679 Append text from a buffer.
681 .B "[count] r <character>"
686 .B "[buffer] [count] s"
689 characters in the current line starting with the current character.
691 .B "[count] t <character>"
694 times, through the current line for the character immediately
699 Undo the last change made to the file.
706 .B "[buffer] [count] x"
711 .B "[buffer] [count] y motion"
713 a text region specified by the
715 and motion into a buffer.
717 .B "[count1] z [count2] -|.|+|^|<carriage-return>"
718 Redraw, optionally repositioning and resizing the screen.
728 position on the current line.
736 Reverse the case of the next
740 .B "[count] ~ motion"
741 Reverse the case of the characters in a text region specified by the
747 Interrupt the current operation.
748 .SH VI TEXT INPUT COMMANDS
749 The following section describes the commands available in the text
756 Replay the previous input.
759 Erase to the previous
764 Erase all of the autoindent characters, and reset the autoindent level.
767 Erase all of the autoindent characters.
774 characters to move forward to the next
781 Erase the last character.
784 Quote the next character.
787 Resolve all text input into the file, and return to command mode.
790 Erase the current line.
796 The definition of word is dependent on the
802 .B "<control-X>[0-9A-Fa-f]+"
803 Insert a character with the specified hexadecimal value into the text.
806 Interrupt text input mode, returning to command mode.
808 The following section describes the commands available in the
811 In each entry below, the tag line is a usage synopsis for the command.
819 .B "[range]! argument(s)"
820 Execute a shell command, or filter lines through a shell command.
825 .B "[range] nu[mber] [count] [flags]"
827 .B "[range] # [count] [flags]"
828 Display the selected lines, each preceded with its line number.
835 .B "[line] a[ppend][!]"
836 The input text is appended after the specified line.
838 .B "[range] c[hange][!] [count]"
839 The input text replaces the specified range.
841 .B "cs[cope] add | find | help | kill | reset"
842 Execute a Cscope command.
844 .B "[range] d[elete] [buffer] [count] [flags]"
845 Delete the lines from the file.
847 .B "di[splay] b[uffers] | c[onnections] | s[creens] | t[ags]"
848 Display buffers, Cscope connections, screens or tags.
850 .B "[Ee][dit][!] [+cmd] [file]"
852 .B "[Ee]x[!] [+cmd] [file]"
853 Edit a different file.
855 .B "exu[sage] [command]"
861 Display and optionally change the file name.
866 Foreground the specified screen.
868 .B "[range] g[lobal] /pattern/ [commands]"
870 .B "[range] v /pattern/ [commands]"
871 Apply commands to lines matching (or not matching) a pattern.
874 Display a help message.
876 .B "[line] i[nsert][!]"
877 The input text is inserted before the specified line.
879 .B "[range] j[oin][!] [count] [flags]"
880 Join lines of text together.
882 .B "[range] l[ist] [count] [flags]"
883 Display the lines unambiguously.
885 .B "map[!] [lhs rhs]"
886 Define or display maps (for
890 .B "[line] ma[rk] <character>"
892 .B "[line] k <character>"
893 Mark the line with the mark
896 .B "[range] m[ove] line"
897 Move the specified lines after the target line.
899 .B "mk[exrc][!] file"
900 Write the abbreviations, editor options and maps to the specified
903 .B "[Nn][ext][!] [file ...]"
904 Edit the next file from the argument list.
906 .B "[line] o[pen] /pattern/ [flags]"
910 Save the file in a form that can later be recovered using the
915 .B "[Pp]rev[ious][!]"
916 Edit the previous file from the argument list.
918 .B "[range] p[rint] [count] [flags]"
919 Display the specified lines.
921 .B "[line] pu[t] [buffer]"
922 Append buffer contents to the current line.
925 End the editing session.
927 .B "[line] r[ead][!] [file]"
933 if it was previously saved.
935 .B "res[ize] [+|-]size"
938 Grow or shrink the current screen.
941 Rewind the argument list.
943 .B "se[t] [option[=[value]] ...] [nooption ...] [option? ...] [all]"
944 Display or set editor options.
952 commands from a file.
954 .B "[range] s[ubstitute] [/pattern/replace/] [options] [count] [flags]"
956 .B "[range] & [options] [count] [flags]"
958 .B "[range] ~ [options] [count] [flags]"
966 Suspend the edit session.
968 .B "[Tt]a[g][!] tagstring"
969 Edit the file containing the specified tag.
972 Edit the file containing the next context for the current tag.
974 .B "tagp[op][!] [file | number]"
975 Pop to the specified tag in the tags stack.
978 Edit the file containing the previous context for the current tag.
981 Unmap a mapped string.
984 Display the version of the
988 .B "[line] vi[sual] [type] [count] [flags]"
994 .B "[Vi]i[sual][!] [+cmd] [file]"
999 .B "viu[sage] [command]"
1004 .B "[range] w[rite][!] [>>] [file]"
1006 .B "[range] w[rite] [!] [file]"
1008 .B "[range] wn[!] [>>] [file]"
1010 .B "[range] wq[!] [>>] [file]"
1013 .B "[range] x[it][!] [file]"
1014 Write the file if it has been modified.
1016 .B "[range] ya[nk] [buffer] [count]"
1017 Copy the specified lines to a buffer.
1019 .B "[line] z [type] [count] [flags]"
1022 There are a large number of options that may be set (or unset) to
1023 change the editor's behavior.
1024 This section describes the options, their abbreviations and their
1027 In each entry below, the first part of the tag line is the full name
1028 of the option, followed by any equivalent abbreviations.
1029 The part in square brackets is the default value of the option.
1030 Most of the options are boolean, i.e. they are either on or off,
1031 and do not have an associated value.
1033 Options apply to both
1037 modes, unless otherwise specified.
1040 .B "altwerase [off]"
1043 Select an alternate word erase algorithm.
1045 .B "autoindent, ai [off]"
1046 Automatically indent new lines.
1048 .B "autoprint, ap [off]"
1051 Display the current line automatically.
1053 .B "autowrite, aw [off]"
1054 Write modified files automatically when changing files.
1055 .\" I cannot get a double quote to print between the square brackets
1056 .\" to save my life. The ONLY way I've been able to get this to work
1057 .\" is with the .tr command.
1063 Backup files before they are overwritten.
1065 .B "beautify, bf [off]"
1066 Discard control characters.
1068 .B "cdpath [environment variable CDPATH, or current directory]"
1069 The directory paths used as path prefixes for the
1073 .B "cedit [no default]"
1074 Set the character to edit the colon command-line history.
1076 .B "columns, co [80]"
1077 Set the number of columns in the screen.
1082 Skip leading comments in shell, C and C++ language files.
1084 .B "directory, dir [environment variable TMPDIR, or /tmp]"
1085 The directory where temporary files are created.
1087 .B "edcompatible, ed [off]"
1088 Remember the values of the ``c'' and ``g'' suffices to the
1090 commands, instead of initializing them as unset for each new
1093 .B "errorbells, eb [off]"
1096 Announce error messages with a bell.
1099 Read the startup files in the local directory.
1102 Regular expressions are extended (i.e.
1106 .B "filec [no default]"
1107 Set the character to perform file path completion on the colon
1111 Flash the screen instead of beeping the keyboard on error.
1113 .B "hardtabs, ht [8]"
1114 Set the spacing between hardware tab settings.
1117 Makes all Regular Expressions case-insensitive,
1118 as long as an upper-case letter does not appear in the search string.
1120 .B "ignorecase, ic [off]"
1121 Ignore case differences in regular expressions.
1124 The 10th's of a second
1126 waits for a subsequent key to complete a key mapping.
1128 .B "leftright [off]"
1131 Do left-right scrolling.
1136 Set the number of lines in the screen.
1141 Modify various search commands and options to work with Lisp.
1142 .I "This option is not yet implemented."
1145 Display lines in an unambiguous fashion.
1148 Attempt to get an exclusive lock on any file being edited,
1152 Treat certain characters specially in regular expressions.
1157 The 10th's of a second
1159 pauses on the matching character when the
1164 Permit messages from other users.
1166 .B "modelines, modeline [off]"
1167 Read the first and last few lines of each file for
1170 .I "This option will never be implemented."
1171 .\" I cannot get a double quote to print between the square brackets
1172 .\" to save my life. The ONLY way I've been able to get this to work
1173 .\" is with the .tr command.
1179 Characters that are never handled as printable characters.
1181 .B "number, nu [off]"
1182 Precede each line displayed with its current line number.
1185 Display unknown characters as octal numbers, instead of the default
1191 If this option is not set, the
1195 commands are disallowed.
1197 .B "optimize, opt [on]"
1200 Optimize text throughput to dumb terminals.
1201 .I "This option is not yet implemented."
1203 .B "paragraphs, para [IPLPPPQPP LIpplpipbp]"
1206 Define additional paragraph boundaries for the
1213 Define additional directories to search for files being edited.
1214 .\" I cannot get a double quote to print between the square brackets
1215 .\" to save my life. The ONLY way I've been able to get this to work
1216 .\" is with the .tr command.
1222 Characters that are always handled as printable characters.
1227 Display a command prompt.
1229 .B "readonly, ro [off]"
1230 Mark the file and session as read-only.
1232 .B "recdir [/var/tmp/vi.recover]"
1233 The directory where recovery files are stored.
1235 .B "redraw, re [off]"
1238 Simulate an intelligent terminal on a dumb one.
1239 .I "This option is not yet implemented."
1242 Remap keys until resolved.
1245 Set the number of lines about which the editor reports changes
1251 Display a row/column ruler on the colon command line.
1253 .B "scroll, scr [window / 2]"
1254 Set the number of lines scrolled.
1256 .B "searchincr [off]"
1261 commands incremental.
1263 .B "sections, sect [NHSHH HUnhsh]"
1266 Define additional section boundaries for the
1273 Turns off all access to external programs.
1275 .B "shell, sh [environment variable SHELL, or /bin/sh]"
1276 Select the shell used by the editor.
1277 .\" I cannot get a double quote to print between the square brackets
1278 .\" to save my life. The ONLY way I've been able to get this to work
1279 .\" is with the .tr command.
1281 .ds ms shellmeta [~{[*?$`'Q\e]
1285 Set the meta characters checked to determine if file name expansion
1288 .B "shiftwidth, sw [8]"
1289 Set the autoindent and shift command indentation width.
1291 .B "showmatch, sm [off]"
1294 Note matching ``{'' and ``('' for ``}'' and ``)'' characters.
1296 .B "showmode, smd [off]"
1299 Display the current editor mode and a ``modified'' flag.
1301 .B "sidescroll [16]"
1304 Set the amount a left-right scroll will shift.
1306 .B "slowopen, slow [off]"
1307 Delay display updating during text input.
1308 .I "This option is not yet implemented."
1310 .B "sourceany [off]"
1311 Read startup files not owned by the current user.
1312 .I "This option will never be implemented."
1314 .B "tabstop, ts [8]"
1315 This option sets tab widths for the editor display.
1317 .B "taglength, tl [0]"
1318 Set the number of significant characters in tag names.
1320 .B "tags, tag [tags /var/db/libc.tags /sys/kern/tags]"
1321 Set the list of tags files.
1323 .B "term, ttytype, tty [environment variable TERM]"
1324 Set the terminal type.
1327 This option has historically made editor messages less verbose.
1328 It has no effect in this implementation.
1333 command to take an associated motion.
1335 .B "timeout, to [on]"
1336 Time out on keys which may be mapped.
1338 .B "ttywerase [off]"
1341 Select an alternate erase algorithm.
1346 Display an error message for every error.
1348 .B "w300 [no default]"
1351 Set the window size if the baud rate is less than 1200 baud.
1353 .B "w1200 [no default]"
1356 Set the window size if the baud rate is equal to 1200 baud.
1358 .B "w9600 [no default]"
1361 Set the window size if the baud rate is greater than 1200 baud.
1366 This option causes a warning message to the terminal if the file has
1367 been modified, since it was last written, before a
1371 .B "window, w, wi [environment variable LINES]"
1372 Set the window size for the screen.
1374 .B "windowname [off]"
1375 Change the icon/window name to the current file name even if it can't
1376 be restored on editor exit.
1378 .B "wraplen, wl [0]"
1381 Break lines automatically, the specified number of columns from the
1387 edit options are set, the
1391 .B "wrapmargin, wm [0]"
1394 Break lines automatically, the specified number of columns from the
1400 edit options are set, the
1404 .B "wrapscan, ws [on]"
1405 Set searches to wrap around the end or beginning of the file.
1407 .B "writeany, wa [off]"
1408 Turn off file-overwriting checks.
1409 .SH "ENVIRONMENT VARIABLES
1412 The number of columns on the screen.
1413 This value overrides any system or terminal specific values.
1416 environmental variable is not set when
1420 option is explicitly reset by the user,
1422 enters the value into the environment.
1427 startup commands, read if the variable
1432 The user's home directory, used as the initial directory path
1433 for the startup ``$\fIHOME\fP/.nexrc'' and ``$\fIHOME\fP/.exrc''
1435 This value is also used as the default directory for the
1441 The number of rows on the screen.
1442 This value overrides any system or terminal specific values.
1445 environmental variable is not set when
1449 option is explicitly reset by the user,
1451 enters the value into the environment.
1459 The user's shell of choice (see also the
1464 The user's terminal type.
1465 The default is the type ``unknown''.
1468 environmental variable is not set when
1472 option is explicitly reset by the user,
1474 enters the value into the environment.
1477 The location used to stored temporary files (see also the
1480 .SH ASYNCHRONOUS EVENTS
1484 uses this signal for periodic backups of file modifications and to
1485 display ``busy'' messages when operations are likely to take a long time.
1490 If the current buffer has changed since it was last written in its
1491 entirety, the editor attempts to save the modified file so it can
1495 Reference manual section entitled ``Recovery'' for more information.
1498 When an interrupt occurs,
1499 the current operation is halted,
1500 and the editor returns to the command level.
1501 If interrupted during text input,
1502 the text already input is resolved into the file as if the text
1503 input had been normally terminated.
1506 The screen is resized.
1509 Reference manual section entitled ``Sizing the Screen'' for more information.
1517 ignores these signals.
1521 The default user shell.
1524 System-wide vi startup file.
1527 Temporary file directory.
1530 The default recovery file directory.
1533 1st choice for user's home directory startup file.
1536 2nd choice for user's home directory startup file.
1539 1st choice for local directory startup file.
1542 2nd choice for local directory startup file.
1549 The ``Vi Quick Reference'' card.
1551 ``An Introduction to Display Editing with Vi'', found in the
1552 ``UNIX User's Manual Supplementary Documents''
1553 section of both the 4.3BSD and 4.4BSD manual sets.
1554 This document is the closest thing available to an introduction to the
1558 ``Ex Reference Manual (Version 3.7)'',
1560 ``UNIX User's Manual Supplementary Documents''
1561 section of both the 4.3BSD and 4.4BSD manual sets.
1562 This document is the final reference for the
1564 editor, as distributed in most historic 4BSD and System V systems.
1566 ``Edit: A tutorial'',
1568 ``UNIX User's Manual Supplementary Documents''
1569 section of the 4.3BSD manual set.
1570 This document is an introduction to a simple version of the
1574 ``Ex/Vi Reference Manual'',
1576 ``UNIX User's Manual Supplementary Documents''
1577 section of the 4.4BSD manual set.
1578 This document is the final reference for the
1580 text editors, as distributed in 4.4BSD and 4.4BSD-Lite.
1583 source for all of these documents is distributed with
1591 The files ``autowrite'', ``input'', ``quoting'' and ``structures''
1593 .I nvi/docs/internals
1600 replacements for the
1602 editor first appeared in 4.4BSD.
1605 is close to IEEE Std1003.2 (``POSIX'').
1606 That document differs from historical
1608 practice in several places; there are changes to be made on both sides.