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 Start editing with the lisp and showmatch options set.
120 Start editing in read-only mode, as if the command name was
127 Recover the specified files, or, if no files are specified,
128 list the files that could be recovered.
129 If no recoverable files by the specified name exist,
130 the file is edited as if the
132 option had not been specified.
137 edit option set, disallowing all access to external programs.
140 Enter batch mode; applicable only to
143 Batch mode is useful when running
146 Prompts, informative messages and other user oriented message
148 and no startup files or environmental variables are read.
149 This is the POSIX 1003.2 interface for the historic ``\-'' argument.
151 supports both the old and new syntax.
154 Start editing at the specified tag.
159 Set the initial window size to the specified number of lines.
162 Start editing in vi mode, as if the command name was
169 is read from the standard input.
172 interface, it is an error if standard input is not a terminal.
175 interface, if standard input is not a terminal,
177 will read commands from it regardless, however, the session will be a
178 batch mode session, exactly as if the
180 option had been specified.
183 exits 0 on success, and greater than 0 if an error occurs.
185 This section will tell you the minimum amount that you need to
186 do simple editing tasks using
188 If you've never used any screen editor before, you're likely to have
189 problems even with this simple introduction.
190 In that case you should find someone that already knows
192 and have them walk you through this section.
196 This means that it takes up almost the entire screen, displaying part
197 of the file on each screen line, except for the last line of the screen.
198 The last line of the screen is used for you to give commands to
202 to give information to you.
204 The other fact that you need to understand is that
206 is a modeful editor, i.e. you are either entering text or you
207 are executing commands, and you have to be in the right mode
208 to do one or the other.
209 You will be in command mode when you first start editing a file.
210 There are commands that switch you into input mode.
211 There is only one key that takes you out of input mode,
212 and that is the <escape> key.
213 (Key names are written using less-than and greater-than signs, e.g.
214 <escape> means the ``escape'' key, usually labeled ``esc'' on your
215 terminal's keyboard.)
216 If you're ever confused as to which mode you're in,
217 keep entering the <escape> key until
222 will beep at you if you try and do something that's not allowed.
223 It will also display error messages.)
225 To start editing a file, enter the command ``vi file_name<carriage-return>''.
226 The command you should enter as soon as you start editing is
227 ``:set verbose showmode<carriage-return>''.
228 This will make the editor give you verbose error messages and display
229 the current mode at the bottom of the screen.
231 The commands to move around the file are:
234 Move the cursor left one character.
237 Move the cursor down one line.
240 Move the cursor up one line.
243 Move the cursor right one character.
246 The cursor arrow keys should work, too.
248 .B /text<carriage-return>
249 Search for the string ``text'' in the file,
250 and move the cursor to its first character.
252 The commands to enter new text are:
265 Open a new line below the line the cursor is on, and start
269 Open a new line above the line the cursor is on, and start
273 Once you've entered input mode using the one of the
281 to quit entering text and return to command mode.
283 The commands to copy text are:
286 Copy the line the cursor is on.
289 Append the copied line after the line the cursor is on.
291 The commands to delete text are:
294 Delete the line the cursor is on.
297 Delete the character the cursor is on.
299 The commands to write the file are:
301 .B :w<carriage-return>
302 Write the file back to the file with the name that you originally used
303 as an argument on the
307 .B ":w file_name<carriage-return>"
308 Write the file back to the file with the name ``file_name''.
310 The commands to quit editing and exit the editor are:
312 .B :q<carriage-return>
313 Quit editing and leave vi (if you've modified the file, but not
316 will refuse to quit).
318 .B :q!<carriage-return>
319 Quit, discarding any modifications that you may have made.
322 Unusual characters can take up more than one column on the screen,
323 and long lines can take up more than a single screen line.
324 The above commands work on ``physical'' characters and lines,
325 i.e. they affect the entire line no matter how many screen lines it
326 takes up and the entire character no matter how many screen columns
329 The following section describes the commands available in the command
333 In each entry below, the tag line is a usage synopsis for the command
337 .B "[count] <control-A>"
340 times for the current word.
342 .B "[count] <control-B>"
347 .B "[count] <control-D>"
352 .B "[count] <control-E>"
355 lines, leaving the current line and column as is, if possible.
357 .B "[count] <control-F>"
363 Display the file information.
370 characters in the current line.
372 .B "[count] <control-J>"
374 .B "[count] <control-N>"
379 lines without changing the current column.
386 .B "[count] <control-M>"
391 lines to the first nonblank character of that line.
393 .B "[count] <control-P>"
398 lines, without changing the current column.
401 Return to the most recent tag context.
409 Switch to the next lower screen in the window, or, to the first
410 screen if there are no lower screens in the window.
415 lines, leaving the current line and column as is, if possible.
418 Suspend the current editor session.
423 commands or cancel partial commands.
426 Push a tag reference onto the tag stack.
429 Switch to the most recently edited file.
434 Move the cursor forward
436 characters without changing the current line.
438 .B "[count] ! motion shell-argument(s)"
439 Replace text with results from a shell command.
442 Increment or decrement the cursor number.
445 Move the cursor to the end of a line.
448 Move to the matching character.
451 Repeat the previous substitution command on the current line.
456 Return to a context marked by the character
470 Reverse find character
475 Move to first nonblank of the previous line,
482 command that modified text.
484 .B "/RE<carriage-return>"
486 .B "/RE/ [offset]<carriage-return>"
488 .B "?RE<carriage-return>"
490 .B "?RE? [offset]<carriage-return>"
495 Search forward or backward for a regular expression.
498 Move to the first character in the current line.
501 Execute an ex command.
504 Repeat the last character find
508 .B "[count] < motion"
510 .B "[count] > motion"
511 Shift lines left or right.
514 Execute a named buffer.
517 Enter input mode, appending the text after the end of the line.
524 .B "[buffer] [count] C"
525 Change text from the current position to the end-of-line.
528 Delete text from the current position to the end-of-line.
535 .B "[count] F <character>"
538 times backward through the current line for
544 or the last line of the file if
549 Move to the screen line
551 lines below the top of the screen.
554 Enter input mode, inserting the text at the beginning of the line.
560 Move to the screen line
562 lines above the bottom of the screen.
565 Move to the screen line in the middle of the screen.
568 Enter input mode, appending text in a new line above the current line.
571 Insert text from a buffer.
576 (or visual) mode and switch to
581 Enter input mode, replacing the characters in the current line.
583 .B "[buffer] [count] S"
588 .B "[count] T <character>"
592 through the current line for the character
598 Restore the current line to its state before the cursor last
606 .B "[buffer] [count] X"
609 characters before the cursor.
611 .B "[buffer] [count] Y"
614 lines into the specified buffer.
617 Write the file and exit
631 Move to first nonblank character on the current line.
636 lines, to the first nonblank character.
639 Enter input mode, appending the text after the cursor.
646 .B "[buffer] [count] c motion"
647 Change a region of text.
649 .B "[buffer] [count] d motion"
650 Delete a region of text.
657 .B "[count] f<character>"
660 times, through the rest of the current line for
664 Enter input mode, inserting the text before the cursor.
667 Save the current context (line and column) as
671 Enter input mode, appending text in a new line under the current line.
674 Append text from a buffer.
676 .B "[count] r <character>"
681 .B "[buffer] [count] s"
684 characters in the current line starting with the current character.
686 .B "[count] t <character>"
689 times, through the current line for the character immediately
694 Undo the last change made to the file.
701 .B "[buffer] [count] x"
706 .B "[buffer] [count] y motion"
708 a text region specified by the
710 and motion into a buffer.
712 .B "[count1] z [count2] -|.|+|^|<carriage-return>"
713 Redraw, optionally repositioning and resizing the screen.
723 position on the current line.
731 Reverse the case of the next
735 .B "[count] ~ motion"
736 Reverse the case of the characters in a text region specified by the
742 Interrupt the current operation.
743 .SH VI TEXT INPUT COMMANDS
744 The following section describes the commands available in the text
751 Replay the previous input.
754 Erase to the previous
759 Erase all of the autoindent characters, and reset the autoindent level.
762 Erase all of the autoindent characters.
769 characters to move forward to the next
776 Erase the last character.
779 Quote the next character.
782 Resolve all text input into the file, and return to command mode.
785 Erase the current line.
791 The definition of word is dependent on the
797 .B "<control-X>[0-9A-Fa-f]+"
798 Insert a character with the specified hexadecimal value into the text.
801 Interrupt text input mode, returning to command mode.
803 The following section describes the commands available in the
806 In each entry below, the tag line is a usage synopsis for the command.
814 .B "[range]! argument(s)"
815 Execute a shell command, or filter lines through a shell command.
820 .B "[range] nu[mber] [count] [flags]"
822 .B "[range] # [count] [flags]"
823 Display the selected lines, each preceded with its line number.
830 .B "[line] a[ppend][!]"
831 The input text is appended after the specified line.
833 .B "[range] c[hange][!] [count]"
834 The input text replaces the specified range.
836 .B "cs[cope] add | find | help | kill | reset"
837 Execute a Cscope command.
839 .B "[range] d[elete] [buffer] [count] [flags]"
840 Delete the lines from the file.
842 .B "di[splay] b[uffers] | c[onnections] | s[creens] | t[ags]"
843 Display buffers, Cscope connections, screens or tags.
845 .B "[Ee][dit][!] [+cmd] [file]"
847 .B "[Ee]x[!] [+cmd] [file]"
848 Edit a different file.
850 .B "exu[sage] [command]"
856 Display and optionally change the file name.
861 Foreground the specified screen.
863 .B "[range] g[lobal] /pattern/ [commands]"
865 .B "[range] v /pattern/ [commands]"
866 Apply commands to lines matching (or not matching) a pattern.
869 Display a help message.
871 .B "[line] i[nsert][!]"
872 The input text is inserted before the specified line.
874 .B "[range] j[oin][!] [count] [flags]"
875 Join lines of text together.
877 .B "[range] l[ist] [count] [flags]"
878 Display the lines unambiguously.
880 .B "map[!] [lhs rhs]"
881 Define or display maps (for
885 .B "[line] ma[rk] <character>"
887 .B "[line] k <character>"
888 Mark the line with the mark
891 .B "[range] m[ove] line"
892 Move the specified lines after the target line.
894 .B "mk[exrc][!] file"
895 Write the abbreviations, editor options and maps to the specified
898 .B "[Nn][ext][!] [file ...]"
899 Edit the next file from the argument list.
901 .B "[line] o[pen] /pattern/ [flags]"
905 Save the file in a form that can later be recovered using the
910 .B "[Pp]rev[ious][!]"
911 Edit the previous file from the argument list.
913 .B "[range] p[rint] [count] [flags]"
914 Display the specified lines.
916 .B "[line] pu[t] [buffer]"
917 Append buffer contents to the current line.
920 End the editing session.
922 .B "[line] r[ead][!] [file]"
928 if it was previously saved.
930 .B "res[ize] [+|-]size"
933 Grow or shrink the current screen.
936 Rewind the argument list.
938 .B "se[t] [option[=[value]] ...] [nooption ...] [option? ...] [all]"
939 Display or set editor options.
947 commands from a file.
949 .B "[range] s[ubstitute] [/pattern/replace/] [options] [count] [flags]"
951 .B "[range] & [options] [count] [flags]"
953 .B "[range] ~ [options] [count] [flags]"
961 Suspend the edit session.
963 .B "[Tt]a[g][!] tagstring"
964 Edit the file containing the specified tag.
967 Edit the file containing the next context for the current tag.
969 .B "tagp[op][!] [file | number]"
970 Pop to the specified tag in the tags stack.
973 Edit the file containing the previous context for the current tag.
976 Unmap a mapped string.
979 Display the version of the
983 .B "[line] vi[sual] [type] [count] [flags]"
989 .B "[Vi]i[sual][!] [+cmd] [file]"
994 .B "viu[sage] [command]"
999 .B "[range] w[rite][!] [>>] [file]"
1001 .B "[range] w[rite] [!] [file]"
1003 .B "[range] wn[!] [>>] [file]"
1005 .B "[range] wq[!] [>>] [file]"
1008 .B "[range] x[it][!] [file]"
1009 Write the file if it has been modified.
1011 .B "[range] ya[nk] [buffer] [count]"
1012 Copy the specified lines to a buffer.
1014 .B "[line] z [type] [count] [flags]"
1017 There are a large number of options that may be set (or unset) to
1018 change the editor's behavior.
1019 This section describes the options, their abbreviations and their
1022 In each entry below, the first part of the tag line is the full name
1023 of the option, followed by any equivalent abbreviations.
1024 The part in square brackets is the default value of the option.
1025 Most of the options are boolean, i.e. they are either on or off,
1026 and do not have an associated value.
1028 Options apply to both
1032 modes, unless otherwise specified.
1035 .B "altwerase [off]"
1038 Select an alternate word erase algorithm.
1040 .B "autoindent, ai [off]"
1041 Automatically indent new lines.
1043 .B "autoprint, ap [off]"
1046 Display the current line automatically.
1048 .B "autowrite, aw [off]"
1049 Write modified files automatically when changing files.
1050 .\" I cannot get a double quote to print between the square brackets
1051 .\" to save my life. The ONLY way I've been able to get this to work
1052 .\" is with the .tr command.
1058 Backup files before they are overwritten.
1060 .B "beautify, bf [off]"
1061 Discard control characters.
1063 .B "cdpath [environment variable CDPATH, or current directory]"
1064 The directory paths used as path prefixes for the
1068 .B "cedit [no default]"
1069 Set the character to edit the colon command-line history.
1071 .B "columns, co [80]"
1072 Set the number of columns in the screen.
1077 Skip leading comments in shell, C and C++ language files.
1079 .B "directory, dir [environment variable TMPDIR, or /tmp]"
1080 The directory where temporary files are created.
1082 .B "edcompatible, ed [off]"
1083 Remember the values of the ``c'' and ``g'' suffices to the
1085 commands, instead of initializing them as unset for each new
1088 .B "errorbells, eb [off]"
1091 Announce error messages with a bell.
1094 Read the startup files in the local directory.
1097 Regular expressions are extended (i.e.
1101 .B "filec [no default]"
1102 Set the character to perform file path completion on the colon
1106 Flash the screen instead of beeping the keyboard on error.
1108 .B "hardtabs, ht [8]"
1109 Set the spacing between hardware tab settings.
1112 Makes all Regular Expressions case-insensitive,
1113 as long as an upper-case letter does not appear in the search string.
1115 .B "ignorecase, ic [off]"
1116 Ignore case differences in regular expressions.
1119 The 10th's of a second
1121 waits for a subsequent key to complete a key mapping.
1123 .B "leftright [off]"
1126 Do left-right scrolling.
1131 Set the number of lines in the screen.
1136 Modify various search commands and options to work with Lisp.
1137 .I "This option is not yet implemented."
1140 Display lines in an unambiguous fashion.
1143 Attempt to get an exclusive lock on any file being edited,
1147 Treat certain characters specially in regular expressions.
1152 The 10th's of a second
1154 pauses on the matching character when the
1159 Permit messages from other users.
1161 .B "modelines, modeline [off]"
1162 Read the first and last few lines of each file for
1165 .I "This option will never be implemented."
1166 .\" I cannot get a double quote to print between the square brackets
1167 .\" to save my life. The ONLY way I've been able to get this to work
1168 .\" is with the .tr command.
1174 Characters that are never handled as printable characters.
1176 .B "number, nu [off]"
1177 Precede each line displayed with its current line number.
1180 Display unknown characters as octal numbers, instead of the default
1186 If this option is not set, the
1190 commands are disallowed.
1192 .B "optimize, opt [on]"
1195 Optimize text throughput to dumb terminals.
1196 .I "This option is not yet implemented."
1198 .B "paragraphs, para [IPLPPPQPP LIpplpipbp]"
1201 Define additional paragraph boundaries for the
1208 Define additional directories to search for files being edited.
1209 .\" I cannot get a double quote to print between the square brackets
1210 .\" to save my life. The ONLY way I've been able to get this to work
1211 .\" is with the .tr command.
1217 Characters that are always handled as printable characters.
1222 Display a command prompt.
1224 .B "readonly, ro [off]"
1225 Mark the file and session as read-only.
1227 .B "recdir [/var/tmp/vi.recover]"
1228 The directory where recovery files are stored.
1230 .B "redraw, re [off]"
1233 Simulate an intelligent terminal on a dumb one.
1234 .I "This option is not yet implemented."
1237 Remap keys until resolved.
1240 Set the number of lines about which the editor reports changes
1246 Display a row/column ruler on the colon command line.
1248 .B "scroll, scr [window / 2]"
1249 Set the number of lines scrolled.
1251 .B "searchincr [off]"
1256 commands incremental.
1258 .B "sections, sect [NHSHH HUnhsh]"
1261 Define additional section boundaries for the
1268 Turns off all access to external programs.
1270 .B "shell, sh [environment variable SHELL, or /bin/sh]"
1271 Select the shell used by the editor.
1272 .\" I cannot get a double quote to print between the square brackets
1273 .\" to save my life. The ONLY way I've been able to get this to work
1274 .\" is with the .tr command.
1276 .ds ms shellmeta [~{[*?$`'Q\e]
1280 Set the meta characters checked to determine if file name expansion
1283 .B "shiftwidth, sw [8]"
1284 Set the autoindent and shift command indentation width.
1286 .B "showmatch, sm [off]"
1289 Note matching ``{'' and ``('' for ``}'' and ``)'' characters.
1291 .B "showmode, smd [off]"
1294 Display the current editor mode and a ``modified'' flag.
1296 .B "sidescroll [16]"
1299 Set the amount a left-right scroll will shift.
1301 .B "slowopen, slow [off]"
1302 Delay display updating during text input.
1303 .I "This option is not yet implemented."
1305 .B "sourceany [off]"
1306 Read startup files not owned by the current user.
1307 .I "This option will never be implemented."
1309 .B "tabstop, ts [8]"
1310 This option sets tab widths for the editor display.
1312 .B "taglength, tl [0]"
1313 Set the number of significant characters in tag names.
1315 .B "tags, tag [tags /var/db/libc.tags /sys/kern/tags]"
1316 Set the list of tags files.
1318 .B "term, ttytype, tty [environment variable TERM]"
1319 Set the terminal type.
1322 This option has historically made editor messages less verbose.
1323 It has no effect in this implementation.
1328 command to take an associated motion.
1330 .B "timeout, to [on]"
1331 Time out on keys which may be mapped.
1333 .B "ttywerase [off]"
1336 Select an alternate erase algorithm.
1341 Display an error message for every error.
1343 .B "w300 [no default]"
1346 Set the window size if the baud rate is less than 1200 baud.
1348 .B "w1200 [no default]"
1351 Set the window size if the baud rate is equal to 1200 baud.
1353 .B "w9600 [no default]"
1356 Set the window size if the baud rate is greater than 1200 baud.
1361 This option causes a warning message to the terminal if the file has
1362 been modified, since it was last written, before a
1366 .B "window, w, wi [environment variable LINES]"
1367 Set the window size for the screen.
1369 .B "windowname [off]"
1370 Change the icon/window name to the current file name even if it can't
1371 be restored on editor exit.
1373 .B "wraplen, wl [0]"
1376 Break lines automatically, the specified number of columns from the
1382 edit options are set, the
1386 .B "wrapmargin, wm [0]"
1389 Break lines automatically, the specified number of columns from the
1395 edit options are set, the
1399 .B "wrapscan, ws [on]"
1400 Set searches to wrap around the end or beginning of the file.
1402 .B "writeany, wa [off]"
1403 Turn off file-overwriting checks.
1404 .SH "ENVIRONMENT VARIABLES
1407 The number of columns on the screen.
1408 This value overrides any system or terminal specific values.
1411 environmental variable is not set when
1415 option is explicitly reset by the user,
1417 enters the value into the environment.
1422 startup commands, read if the variable
1427 The user's home directory, used as the initial directory path
1428 for the startup ``$\fIHOME\fP/.nexrc'' and ``$\fIHOME\fP/.exrc''
1430 This value is also used as the default directory for the
1436 The number of rows on the screen.
1437 This value overrides any system or terminal specific values.
1440 environmental variable is not set when
1444 option is explicitly reset by the user,
1446 enters the value into the environment.
1454 The user's shell of choice (see also the
1459 The user's terminal type.
1460 The default is the type ``unknown''.
1463 environmental variable is not set when
1467 option is explicitly reset by the user,
1469 enters the value into the environment.
1472 The location used to stored temporary files (see also the
1475 .SH ASYNCHRONOUS EVENTS
1479 uses this signal for periodic backups of file modifications and to
1480 display ``busy'' messages when operations are likely to take a long time.
1485 If the current buffer has changed since it was last written in its
1486 entirety, the editor attempts to save the modified file so it can
1490 Reference manual section entitled ``Recovery'' for more information.
1493 When an interrupt occurs,
1494 the current operation is halted,
1495 and the editor returns to the command level.
1496 If interrupted during text input,
1497 the text already input is resolved into the file as if the text
1498 input had been normally terminated.
1501 The screen is resized.
1504 Reference manual section entitled ``Sizing the Screen'' for more information.
1512 ignores these signals.
1516 The default user shell.
1519 System-wide vi startup file.
1522 Temporary file directory.
1525 The default recovery file directory.
1528 1st choice for user's home directory startup file.
1531 2nd choice for user's home directory startup file.
1534 1st choice for local directory startup file.
1537 2nd choice for local directory startup file.
1544 The ``Vi Quick Reference'' card.
1546 ``An Introduction to Display Editing with Vi'', found in the
1547 ``UNIX User's Manual Supplementary Documents''
1548 section of both the 4.3BSD and 4.4BSD manual sets.
1549 This document is the closest thing available to an introduction to the
1553 ``Ex Reference Manual (Version 3.7)'',
1555 ``UNIX User's Manual Supplementary Documents''
1556 section of both the 4.3BSD and 4.4BSD manual sets.
1557 This document is the final reference for the
1559 editor, as distributed in most historic 4BSD and System V systems.
1561 ``Edit: A tutorial'',
1563 ``UNIX User's Manual Supplementary Documents''
1564 section of the 4.3BSD manual set.
1565 This document is an introduction to a simple version of the
1569 ``Ex/Vi Reference Manual'',
1571 ``UNIX User's Manual Supplementary Documents''
1572 section of the 4.4BSD manual set.
1573 This document is the final reference for the
1575 text editors, as distributed in 4.4BSD and 4.4BSD-Lite.
1578 source for all of these documents is distributed with
1586 The files ``autowrite'', ``input'', ``quoting'' and ``structures''
1588 .I nvi/docs/internals
1595 replacements for the
1597 editor first appeared in 4.4BSD.
1600 is close to IEEE Std1003.2 (``POSIX'').
1601 That document differs from historical
1603 practice in several places; there are changes to be made on both sides.