This commit was generated by cvs2svn to track changes on a CVS vendor
[unix-history] / usr.bin / vi / vi.1
CommitLineData
0d19c241
JH
1.\" Copyright (c) 1994
2.\" The Regents of the University of California. All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\" must display the following acknowledgement:
14.\" This product includes software developed by the University of
15.\" California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
304585c1 32.\" @(#)vi.1 8.3 (Berkeley) 3/19/94
0d19c241 33.\"
304585c1 34.Dd "March 19, 1994"
0d19c241
JH
35.Dt EX/VI 1
36.Os
304585c1 37.Sh NAME
0d19c241
JH
38.Nm ex, vi, view
39.Nd text editors
40.Sh SYNOPSIS
304585c1
AM
41.Nm \&ex
42.Op Fl eFlRsv
43.Op Fl c Ar cmd
0d19c241
JH
44.Op Fl r Ar file
45.Op Fl t Ar tag
46.Op Fl w Ar size
304585c1
AM
47.Op Fl x Ar \&aw
48.Op Ar "file ..."
49.Nm \&vi
0d19c241 50.Op Fl eFlRv
304585c1 51.Op Fl c Ar cmd
0d19c241
JH
52.Op Fl r Ar file
53.Op Fl t Ar tag
54.Op Fl w Ar size
304585c1
AM
55.Op Fl x Ar \&aw
56.Op Ar "file ..."
57.Nm view
58.Op Fl eFlRv
59.Op Fl c Ar cmd
0d19c241
JH
60.Op Fl r Ar file
61.Op Fl t Ar tag
62.Op Fl w Ar size
304585c1
AM
63.Op Fl x Ar \&aw
64.Op Ar "file ..."
0d19c241 65.Sh DESCRIPTION
304585c1
AM
66.Nm \&Vi
67is a screen oriented text editor.
68.Nm \&Ex
0d19c241 69is a line-oriented text editor.
304585c1
AM
70.Nm \&Ex
71and
72.Nm \&vi
73are different interfaces to the same program,
74and it is possible to switch back and forth during an edit session.
0d19c241 75.Nm View
304585c1 76is the equivalent of using the
0d19c241
JH
77.Fl R
78(read-only) option of
304585c1 79.Nm \&vi .
0d19c241
JH
80.Pp
81This manual page is the one provided with the
304585c1
AM
82.Nm ex/vi
83versions of the
84.Nm ex/vi
85text editors.
86.Nm Ex/vi
0d19c241
JH
87are intended as bug-for-bug compatible replacements for the original
88Fourth Berkeley Software Distribution (4BSD)
304585c1 89.Nm \&ex
0d19c241 90and
304585c1 91.Nm \&vi
0d19c241 92programs.
304585c1
AM
93For the rest of this manual page,
94.Nm ex/vi
95is used only when it's necessary to distinguish it from the historic
96implementations of
97.Nm ex/vi .
98.Pp
99This manual page is intended for users already familiar with
100.Nm ex/vi .
101Anyone else should almost certainly read a good tutorial on the
102editor before this manual page.
103If you're in an unfamiliar environment, and you absolutely have to
104get work done immediately, read the section near the end of this
105manual page, entitled FAST STARTUP.
106It's probably enough to get you going.
0d19c241
JH
107.Pp
108The following options are available:
304585c1 109.Bl -tag -width Ds
0d19c241
JH
110.It Fl c
111Execute
304585c1 112.Ar cmd
0d19c241 113immediately after starting the edit session.
304585c1
AM
114Particularly useful for initial positioning in the file, however
115.Ar cmd
0d19c241
JH
116is not limited to positioning commands.
117This is the POSIX 1003.2 interface for the historic
304585c1 118.Dq "+cmd"
0d19c241 119syntax.
304585c1 120.Nm Ex/vi
0d19c241
JH
121supports both the old and new syntax.
122.It Fl e
304585c1
AM
123Start editing in ex mode, as if the command name were
124.Nm \&ex .
0d19c241
JH
125.It Fl F
126Don't copy the entire file when first starting to edit.
304585c1
AM
127(The default is to make a copy in case someone else modifies
128the file during your edit session.)
0d19c241
JH
129.It Fl l
130List the files that may be recovered using the
131.Fl r
132option of
304585c1
AM
133.Nm \&vi .
134This is the new interface for the historic syntax of the
0d19c241 135.Fl r
304585c1
AM
136option without a file argument.
137.Nm Ex/vi
0d19c241
JH
138supports both the old and new syntax.
139.It Fl R
140Start editing in read-only mode, as if the command name was
304585c1
AM
141.Nm view ,
142or the readonly option was set.
0d19c241
JH
143.It Fl r
144Recover the specified file.
145.It Fl s
146Enter batch mode; applicable only to
304585c1 147.Nm \&ex
0d19c241
JH
148edit sessions.
149Batch mode is useful when running
304585c1 150.Nm \&ex
0d19c241 151scripts.
304585c1
AM
152Prompts, informative messages and other user oriented message
153are turned off,
154and no startup files or environmental variables are read.
0d19c241 155This is the POSIX 1003.2 interface for the historic
304585c1
AM
156.Dq \&\-
157argument.
158.Nm \&Ex/vi
0d19c241
JH
159supports both the old and new syntax.
160.It Fl t
161Start editing at the specified tag.
162(See
163.Xr ctags 1 ).
164.It Fl w
165Set the initial window size to the specified number of lines.
166.It Fl v
167Start editing in vi mode, as if the command name was
304585c1 168.Nm \&vi
0d19c241
JH
169or
170.Nm view .
171.It Fl x
172Reserved for X11 interfaces.
304585c1
AM
173.Em "No X11 support is currently implemented."
174.El
0d19c241 175.Pp
304585c1
AM
176.Nm Ex/vi
177exit 0 on success, and greater than 0 if an error occurs.
178.Sh ENVIRONMENTAL VARIABLES
179.Bl -tag -width XXXX -compact
180.It Ev COLUMNS
181The number of columns on the screen.
182This value overrides any system or terminal specific values.
183If the COLUMNS environmental variable is not set when
184.Nm ex/vi
185runs, or the
186.Sy columns
187option is explicitly reset by the user,
188.Nm ex/vi
189enters the value into the environment.
190.It Ev EXINIT
191A list of
192.Nm \&ex
193startup commands.
194.It Ev HOME
195The user's home directory, used as the initial directory path
196for the startup
197.Pa $HOME/.exrc
198file.
199This value is also used as the default directory for the
200.Nm \&vi
201.Sy \&cd
0d19c241 202command.
304585c1
AM
203.It Ev LINES
204The number of rows on the screen.
205This value overrides any system or terminal specific values.
206If the LINES environmental variable is not set when
207.Nm ex/vi
208runs, or the
209.Sy lines
210option is explicitly reset by the user,
211.Nm ex/vi
212enters the value into the environment.
213.It Ev SHELL
214The user's shell of choice (see also the
215.Sy shell
216option).
217.It Ev TERM
218The user's terminal type.
219The default is the type
220.Dq unknown .
221If the TERM environmental variable is not set when
222.Nm ex/vi
223runs, or the
224.Sy term
225option is explicitly reset by the user,
226.Nm ex/vi
227enters the value into the environment.
228.It Ev TMPDIR
229The location used to stored temporary files (see also the
230.Sy directory
231option).
232.El
233.Sh SET OPTIONS
234#include <set.opt.roff>
235.Sh FAST STARTUP
236This section will tell you the minimum amount that you need to
237do simple editing tasks using
238.Nm \&vi .
239If you've never used any screen editor before, you're likely to have
240problems even with this simple introduction.
241In that case you should find someone that already knows
242.Nm \&vi
243and have them walk you through this section.
0d19c241 244.Pp
304585c1
AM
245.Nm \&Vi
246is a screen editor.
247This means that it takes up almost the entire screen, displaying part
248of the file on each screen line, except for the last line of the screen.
249The last line of the screen is used for you to give commands to
250.Nm \&vi ,
251and for
252.Nm \&vi
253to give information to you.
0d19c241 254.Pp
304585c1
AM
255The other fact that you need to understand is that
256.Nm \&vi
257is a modeful editor, i.e. you are either entering text or you
258are executing commands, and you have to be in the right mode
259to do one or the other.
260You will be in command mode when you first start editing a file.
261There are commands that switch you into input mode.
262There is only one key that takes you out of input mode,
263and that is the <escape> key.
264(Key names are written using less-than and greater-than signs, e.g.
265<escape> means the
266.Dq escape
267key, usually labeled
268.Dq esc
269on your terminal's keyboard.)
270If you're ever confused as to which mode you're in,
271keep entering the <escape> key until
272.Nm \&vi
273beeps at you.
274(Generally,
275.Nm \&vi
276will beep at you if you try and do something that's not allowed.
277It will also display error messages.)
0d19c241 278.Pp
304585c1
AM
279To start editing a file, enter the command
280.Dq Li "vi file_name<carriage-return>" .
281The command you should enter as soon as you start editing is
282.Dq Li ":set verbose showmode<carriage-return>" .
283This will make the editor give you verbose error messages and display
284the current mode at the bottom of the screen.
0d19c241 285.Pp
304585c1
AM
286The commands to move around the file are:
287.Bl -tag -width XXXX -compact
288.It Sy h
289Move the cursor left one character.
290.It Sy j
291Move the cursor down one line.
292.It Sy k
293Move the cursor up one line.
294.It Sy l
295Move the cursor right one character.
296.It Sy <cursor-arrows>
297The cursor arrow keys should work, too.
298.It Sy /text<carriage-return>
299Search for the string
300.Dq text
301in the file, and move the cursor to its first character.
302.El
303.Pp
304The commands to enter new text are:
305.Bl -tag -width XXXX -compact
306.It Sy a
307Append new text,
308.Em after
309the cursor.
310.It Sy i
311Insert new text,
312.Em before
313the cursor.
314.It Sy o
315Open a new line below the line the cursor is on, and start
316entering text.
317.It Sy O
318Open a new line above the line the cursor is on, and start
319entering text.
320.It Sy <escape>
321Once you've entered input mode using the one of the
322.Sy \&a ,
323.Sy \&i ,
324.Sy \&O ,
325or
326.Sy \&o
327commands, use
328.Sy <escape>
329to quit entering text and return to command mode.
330.El
331.Pp
332The commands to copy text are:
333.Bl -tag -width XXXX -compact
334.It Sy yy
335Copy the line the cursor is on.
336.It Sy p
337Append the copied line after the line the cursor is on.
338.El
0d19c241 339.Pp
304585c1
AM
340The commands to delete text are:
341.Bl -tag -width XXXX -compact
342.It Sy dd
343Delete the line the cursor is on.
344.It Sy x
345Delete the character the cursor is on.
346.El
347.Pp
348The commands to write the file are:
349.Bl -tag -width XXXX -compact
350.It Sy :w<carriage-return>
351Write the file back to the file with the name that you originally used
352as an argument on the
353.Nm \&vi
354command line.
355.It Sy :w file_name<carriage-return>
356Write the file back to the file with the name
357.Dq file_name .
358.El
359.Pp
360The commands to quit editing and exit the editor are:
361.Bl -tag -width XXXX -compact
362.It Sy :q<carriage-return>
363Quit editing and leave vi (if you've modified the file, but not
364saved your changes,
365.Nm \&vi
366will refuse to quit).
367.It Sy :q!<carriage-return>
368Quit, discarding any modifications that you may have made.
369.El
370.Pp
371One final caution.
372Unusual characters can take up more than one column on the screen,
373and long lines can take up more than a single screen line.
374The above commands work on
375.Dq physical
376characters and lines, i.e. they affect the entire line no matter
377how many screen lines it takes up and the entire character no matter
378how many screen columns it takes up.
379.Sh BUGS
0d19c241 380See the file
304585c1 381.Pa vi/docs/bugs.current
0d19c241
JH
382for a list of the known bugs in this version.
383.Sh FILES
304585c1
AM
384.Bl -tag -width /var/tmp/vi.recover -compact
385.It Pa /bin/sh
386The default user shell.
387.It Pa /etc/vi.exrc
388System-wide vi startup file.
0d19c241 389.It Pa /tmp
304585c1 390Temporary file directory.
0d19c241 391.It Pa /var/tmp/vi.recover
304585c1
AM
392Recovery file directory.
393.It Pa $HOME/.exrc
394user's home directory startup file.
395.It Pa .exrc
396local directory startup file.
0d19c241
JH
397.El
398.Sh SEE ALSO
399.Xr ctags 1 ,
400.Xr more 1 ,
401.Xr curses 3 ,
402.Xr dbopen 3
403.sp
404The
178c26c5 405.Dq "Vi Quick Reference"
0d19c241
JH
406card.
407.sp
178c26c5 408.Dq "An Introduction to Display Editing with Vi" ,
0d19c241 409found in the
178c26c5 410.Dq "UNIX User's Manual Supplementary Documents" .
0d19c241 411.sp
178c26c5 412.Dq "Edit: A tutorial" ,
0d19c241 413found in the
178c26c5 414.Dq "UNIX User's Manual Supplementary Documents" .
0d19c241 415.sp
304585c1 416.Dq "\&Ex Reference Manual (Version 3.7)" ,
0d19c241 417found in the
178c26c5
JH
418.Dq "UNIX User's Manual Supplementary Documents" .
419.Pp
420.Nm Nroff/troff
421source for the previous three documents are distributed with
304585c1 422.Nm ex/vi
178c26c5 423in the
304585c1 424.Pa vi/docs/USD.doc
178c26c5 425directory of the
304585c1 426.Nm ex/vi
178c26c5 427source code.
0d19c241
JH
428.sp
429The files
304585c1
AM
430.Dq autowrite ,
431.Dq input ,
432.Dq quoting ,
0d19c241 433and
304585c1 434.Dq structures ,
0d19c241 435found in the
304585c1 436.Pa vi/docs/internals
0d19c241 437directory of the
304585c1 438.Nm ex/vi
0d19c241
JH
439source code.
440.Sh HISTORY
441The
0d19c241 442.Nm ex/vi
304585c1
AM
443replacements for the
444.Nm ex/vi
445editor first appeared in 4.4BSD.
0d19c241 446.Sh STANDARDS
304585c1
AM
447.Nm \&Ex/vi
448is close to IEEE Std1003.2 (``POSIX'').
449That document differs from historical
450.Nm ex/vi
451practice in several places; there are changes to be made on both sides.