'\"!  tbl | mmdoc
'\"macro stdmacro
.if n .pH g1.ex @(#)ex	40.7 of 1/4/90
.\" Copyright 1989 AT&T
.nr X
.if \nX=0 .ds x} ex 1 "Editing Utilities" "\&"
.if \nX=1 .ds x} ex 1 "Editing Utilities"
.if \nX=2 .ds x} ex 1 "" "\&"
.if \nX=3 .ds x} ex "" "" "\&"
.TH \*(x}
'\" t
.SH NAME
\f4ex\f1 \- text editor
.SH SYNOPSIS
\f4ex\f1
\f1[\f4\-s\f1]
\f1[\f4\-v\f1]
\f1[\f4\-t\f1
.IR tag ]
\f1[\f4\-r\f1
.IR file ]
\f1[\f4\-L\f1]
\f1[\f4\-R\f1]
\f1[\f4\-x\f1]
\f1[\f4\-C\f1]
\f1[\f4\-c\f1
.IR command ]
.I "file \|.\|.\|."
.SH DESCRIPTION
\f4ex\fP
is the root of a family of editors:
\f4ex\fP
and
\f4vi\fP.
\f4ex\fP
is a superset of
\f4ed\fP,
with the most notable extension being a display editing facility.
Display based editing is the focus of
\f4vi\fP.
.PP
If you have a \s-2CRT\s0 terminal, you may wish to use a display
based editor; in this case
see
\f4vi\fP(1),
which is a command which focuses on the display-editing portion of
\f4ex\fP.
.SS For ed Users
If you have used
\f4ed\fP
you will find that,
in addition to having all of the
\f4ed\fP
commands available,
\f4ex\fP
has a number of additional features useful on CRT terminals.
Intelligent terminals and high speed terminals are very pleasant to  use
with
\f4vi\fP.
Generally, the
\f4ex\fP
editor uses far more of the capabilities of terminals than
\f4ed\fP
does, and uses the terminal capability data base
[see
\f4terminfo\fP(4)]
and the type of the terminal you are using from the environmental variable
.SM TERM
to determine how to drive your terminal efficiently.
The editor makes use of features such as insert and delete character and line
in its
\f4visual\f1
command
(which can be abbreviated \f4vi\f1)
and which is the central mode of editing when using the
\f4vi\fP command.
.\" There is also an interline editing
.\" .B open
.\" (\f4o\f1)
.\" command which works on all terminals.
.PP
\f4ex\fP
contains a number of features for easily viewing the text of the file.
The
\f4z\f1
command gives easy access to windows of text.
Typing
\f4^D\f1
(control-d) causes the editor to scroll a half-window of text
and is more useful for quickly stepping through a file than just typing
return.
Of course, the screen-oriented
\f4visual\f1
mode gives constant access to editing context.
.PP
\f4ex\fP
gives you help when you make mistakes.
The
\f4undo\f1
(\f4u\f1)
command allows you to reverse any single change which goes astray.
\f4ex\fP
gives you a lot of feedback, normally printing changed lines,
and indicates when more than a few lines are affected by a command
so that it is easy to detect when a command has affected more lines
than it should have.
.PP
The editor also normally prevents overwriting existing files, unless you 
edited them, so that you do not accidentally overwrite
a file other than the one you are editing.
If the system (or editor) crashes, or you accidentally hang up the telephone,
you can use the editor
\f4recover\f1
command
(or
\f4\-r\f2 file\f1
option)
to retrieve your work.
This will get you back to within a few lines of where you left off.
.PP
\f4ex\fP
has several features for dealing with more than one file at a time.
You can give it a list of files on the command line
and use the
\f4next\f1
(\f4n\f1) command to deal with each in turn.
The
\f4next\f1
command can also be given a list of file names, or a pattern
as used by the shell to specify a new set of files to be dealt with.
In general, file names in the editor may be formed with full shell
metasyntax.
The metacharacter `%' is also available in forming file names and is replaced
by the name of the current file.
.\" For editing large groups of related files you can use
.\" .I ex's\^
.\" .B tag
.\" command to quickly locate functions and other important points in 
.\" any of the files.
.\" This is useful when working on a large program when you want to quickly
.\" find the definition of a particular function.
.\" The command
.\" .IR ctags
.\" builds a
.\" .I tags\^
.\" file or a group of C programs.
.PP
The editor has a group
of buffers whose names are the \s-1ASCII\s0 lower-case letters
\f1(\f4a\f1-\f4z\f1).
You can place text in these named buffers
where it is available to be inserted elsewhere in the file.
The contents of these buffers remain available when you begin editing a new file
using the
\f4edit\f1
(\f4e\f1)
command.
.PP
There is a command
\f4&\f1
in
\f4ex\fP
which repeats the last
\f4substitute\f1
command.
In addition, there is a
confirmed substitute command.
You give a range of substitutions to be done and the editor interactively
asks whether each substitution is desired.
.PP
It is possible to ignore the case
of letters in searches and substitutions.
\f4ex\fP
also allows regular expressions which match words to be constructed.
This is convenient, for example, in searching for the word
``edit'' if your document also contains the word ``editor.''
.PP
\f4ex\fP
has a set of
options
which you can set to tailor it to your liking.
One option which is very useful is the
\f4autoindent\f1
option that allows the editor to supply leading white
space to align text automatically.
You can then use
\f4^D\f1
as a backtab
and space or tab to move forward to align new code easily.
.PP
Miscellaneous useful features include an intelligent
\f4join\f1
(\f4j\f1) command that supplies white space between joined lines
automatically,
commands \f4<\f1 and \f4>\f1 which shift groups of lines,
and the ability to filter
portions of the buffer through commands such as
\f4sort\fP.
.SS Invocation Options
The following invocation options are interpreted by
\f4ex\fP
(previously documented options are discussed in the
.SM
\f3NOTES\f1
section at the end of this manual page):
.TP 12
\f4\-s\f1
Suppress all interactive-user feedback.
This is useful in processing editor scripts.
.TP
\f4\-v\f1
Invoke
\f4vi\fP.
.TP
\f4\-t\f2 tag\f1
Edit the file containing the 
.I tag\^
and position the editor at its definition.
.TP
\f4\-r\f2 file\f1
Edit
.I file\^
after an editor or system crash.
(Recovers the version of
.I file
that was in the buffer when the
crash occurred.)
.TP
\f4\-L\f1
List the names of all files saved as the
result of an editor or system crash.
.TP
\f4\-R\f1
\f4Readonly\f1 mode;
the
\f4readonly\f1
flag is set, preventing accidental
overwriting of the file.
.TP
\f4\-x\f1
Encryption option; when used,
\f4ex\fP
simulates an
\f4X\f1
command and prompts the user for a key.
This key is used to encrypt and decrypt
text using the algorithm of the
\f4crypt\fP command.
The
\f4X\f1
command
makes an educated guess to determine whether text
read in is encrypted or not.
The temporary buffer file is encrypted also,
using a transformed version of the key
typed in for the
\f4\-x\f1
option.
See
\f4crypt\fP(1).
Also, see the
.SM
\f3NOTES\f1
section at the end
of this manual page.
.TP
\f4\-C\f1
Encryption option; the same as the
\f4\-x\f1
option, except that
\f4ex\fP
simulates a
\f4C\f1
command.
The
\f4C\f1
command is like the
\f4X\f1
command,
except that
all text read in is assumed to have been encrypted.
.TP
\f4\-c\f2 command\f1
Begin editing by executing the specified editor
.I command\^
(usually a search or positioning command).
.PP
The 
.I file\^
argument indicates one or more files to be edited.
.SS "ex States"
.TP 12
Command
Normal and initial state.  Input prompted for by \f4:\fP.
Your line kill character cancels a partial command.
.TP
Insert
Entered by \f4a\fP, \f4i\fP, or \f4c\fP.
Arbitrary text may be entered.
Insert state normally is  terminated by a line having only "\f4.\f1"
on it,
or, abnormally, with an interrupt.
.TP
.\" Open/visual
.\" Entered by \f4open\fP or \f4vi\fP, terminates with \f4Q\fP
Visual
Entered by typing \f4vi\fP; terminated by typing \f4Q\fP
or ^\^\e (control-\e).
.br
.SS "ex Command Names and Abbreviations"
.TS
l lf4 l lf4 l lf4.
abbrev	ab	map		set	se
append	a	mark	ma	shell	sh
args	ar	move	m	source	so
change	c	next	n	substitute	s
copy	co	number	nu	unabbrev	unab
delete	d	preserve	pre	undo	u
edit	e	print	p	unmap	unm
file	f	put	pu	version	ve
global	g	quit	q	visual	vi
insert	i	read	r	write	w
join	j	recover	rec	xit	x
list	l	rewind	rew	yank	ya
.TE
.SS "ex Commands"
.TS
lw(.45i) lw(.08i)f4 lw(.45i) lw(.08i)f4.
forced encryption	C	heuristic encryption	X
resubst	&	print next	\f1CR\fP
rshift	>	lshift	<
scroll	^D	window	z
shell escape	!
.TE
.SS "ex Command Addresses"
.TS
lw(.3i)f4 lw(0.8i) lw(.3i)f4 lw(0.8i).
\f2n\fP	line \f2n\fP	/\f2pat\fP	next with \f2pat\fP
\&.	current	?\f2pat\fP	previous with \f2pat\fP
$	last	\f2x\fP-\f2n\fP	\f2n\fP before \f2x\fP
+	next	\f2x\fP,\f2y\fP	\f2x\fP through \f2y\fP
\-	previous	\(aa\f2x\fP	marked with \f2x\fP
+\f2n\fP	\f2n\fP forward	\(aa\(aa	previous context
%	1,$
.TE
.br
.ne1.5i
.SS "Initializing options"
.TS
lw(.9i)f4 aw(1.5i).
EXINIT	place \f4set\fP's here in environment variable
$HOME/.exrc	editor initialization file
\&./.exrc  	editor initialization file
set \f2x\fP	enable option \f2x\f1
set no\f2x\fP	disable option \f2x\f1
set \f2x\fP=\f4val\fP	give value \f2val\fP to option \f2x\f1
set	show changed options
set all	show all options
set \f2x\fP?	show value of option \f2x\fP
.TE
.SS "Most useful options and their abbreviations"
.TS
lw(.9i) lw(.3i)f4 lw(1.0i).
autoindent	ai	supply indent
autowrite	aw	write before changing files
directory		pathname of directory for temporary work files
exrc	ex	T{
.na
.in +1
.ti -1
allow \f4vi\fP/\f4ex\fP to read the \f4.exrc\f1
in the current directory.
This option is set in the \f4EXINIT\f1 shell variable
or in the \f4.exrc\f1 file in the \f4$HOME\f1 directory.
.in -1
T}
ignorecase	ic	ignore case of letters in scanning
list		print \f4^I\f1 for tab, $ at end
magic		treat \f4. [ *\fP special in patterns
modelines	\&	T{
.na
.in +1
.ti -1
first five lines and last five lines executed as 
\f4vi\fP/\f4ex\fP commands if they are of the form
\f4ex:\fP\f2command\f1\f4:\fP or \f4vi:\fP\f2command\f1\f4:\fP
.in -1
T}
number	nu	number lines
paragraphs	para	macro names that start paragraphs
redraw		simulate smart terminal
report	\&	T{
.in +1
.ti -1
informs you if the number of lines modified
by the last command is greater than the
value of the \f4report\f1 variable
.in -1
T}
scroll		command mode lines
sections	sect	macro names that start sections
shiftwidth	sw	for \f4< >\fP, and input \f4^D\fP
showmatch	sm	to \f4)\fP and \f4}\fP as typed
showmode	smd	show insert mode in \f4vi\fP
slowopen	slow	stop updates during insert
term		T{
.in +1
.ti -1
specifies to \f4vi\f1 the type of terminal
being used (the default is the value
of the environmental variable \f4\s-1TERM\s0\f1)
.in -1
T}
window		visual mode lines
wrapmargin	wm	automatic line splitting
wrapscan	ws	search around end (or beginning) of buffer
.TE
.br
.ne1.5i
.SS "Scanning pattern formation"
.TS
aw(.9i)b aw(1.0i).
^	beginning of line
$	end of line
\f4\&.\f1	any character
\e<	beginning of word
\e>	end of word
[\f4str\fP]	any character in \f2str\fP
[^\f4str\fP]	any character not in \f2str\fP
[\f2x\-y\fP]	any character between \f2x\fP and \f2y\fP
*	any number of preceding characters
.TE
.br
.ne 5
.SH AUTHOR
\f4vi\fP
and
\f4ex\fP
are based on software developed by
The University of California,
Berkeley California,
Computer Science Division,
Department of Electrical Engineering and Computer Science.
.SH FILES
.TS
lw(.9i)f4 aw(1.5i).
/usr/lib/exstrings	error messages
/usr/lib/exrecover	recover command
/usr/lib/expreserve	preserve command
/usr/share/lib/terminfo/\(**	describes capabilities of terminals
$HOME/.exrc	editor startup file
\&./.exrc  	editor startup file
/tmp/Ex\f2nnnnn\f1	editor temporary
/tmp/Rx\f2nnnnn\f1	named buffer temporary
/var/preserve/\f4login\fP	preservation directory
	(where \f4login\fP is the user's login)
.TE
.SH NOTES
Several options, although they continue to be supported,
have been replaced in the documentation by options that follow
the Command Syntax Standard [see \f4intro\fP(1)].
The
\f4\-\f1
option has been replaced by
\f4\-s\f1,
a
\f4\-r\f1
option that is not followed with an option-argument has been replaced by
\f4\-L\f1,
and
\f4+\f2command\f1
has been replaced by
\f4\-c\f1
.IR command .
.P
The encryption options and commands are provided
with the Security Administration Utilities package,
which is available only in the United States.
.P
The
\f4z\^\f1
command prints the number of logical rather than physical lines.
More than a screen full of output may result if long lines are present.
.PP
File input/output errors do not print a name
if the command line \f4\-s\f1 option is used.
.PP
There is no easy way to do a single scan ignoring case.
.PP
The editor does not warn if text is placed in named buffers
and not used before exiting the editor.
.PP
Null characters are discarded in input files
and cannot appear in resultant files.
.br
.ne1i
.SH SEE ALSO
\f4crypt\fP(1),
\f4ed\fP(1),
\f4edit\fP(1),
\f4grep\fP(1),
\f4sed\fP(1),
\f4sort\fP(1),
\f4vi\fP(1).
.br
\f4curses\fP(3X),
in the \f2Programmer's Reference Manual\f1.
.br
\f4term\fP(4),
\f4terminfo\fP(4)
in the \f2System Administrator's Reference Manual\f1.
.br
\f2User's Guide\f1.
.br
\f2Editing Guide\f1.
.br
curses/terminfo chapter of the
.IR "Programmer's Guide" .
.\"	@(#)ex_x.1	6.2 of 9/2/83
.Ee
