1BSD/exrefm/exrefm8.n

.if !\n(xx .so tmac.e
.SH
Visual and open modes
.PP
.Ex
has two modes,
.I visual
and
.I open ,
which are quite different from command mode.
In command mode,
one prepares command lines which are then executed as they are sent to the
editor.
The editor maintains only a notion of a current line in command mode,
not of a current position within that line.
.PP
In
.I open
and
.I visual
modes,
there is both a current line and a current position within that line.
The cursor appears on the current line, and indicates the current
position within that line by its position.
One then forms
.I operations
consisting of one or more operation characters which are immediately
acted upon by the editor.
Most operation characters do not show on the screen,
rather their effect on the contents of the buffer is shown.
Operation sequences do not form ``lines'' of input,
and do not need to be terminated by a new-line character.
.PP
.B Operations.
Becoming proficient at using
.I open
or
.I visual
thus requires learning a set of
.I operations
which you can use to modify the text of your file.
There are a large number of operations.
They are associated with keys so as to suggest their function.
Related functions are often performed by the upper case counterpart of
a lower case operation.
Thus the `f' find operation moves the cursor to the following
specified character in the forward direction within the line, while `F'
performs the same function in the backward direction.
Similarly, `r' replaces the character under the cursor with the single
following character, while `R' replaces successive text line characters
with the input characters up to a terminating \s-2ESC\s0.
It is not necessary to learn all or nearly all of the available operations
in
.I open
and
.I visual .
As you become more proficient with
.I open
and
.I visual
you may find use for more of them.
.PP
.B "Intraline operations."
There are two major kinds of operations in
.I visual
and
.I open
\- those dealing with the characters of a single line,
and those dealing with the lines themselves.
The intraline operations deal with the text of a single line.
The editor has facilities for referring to the line in terms
of a number of characters, a column position, a number of ``words'',
a target character, the beginning of the line, the first non-blank
character on the line, the end of the line, etc.
In addition these operations will take
.I counts
repeating their effect whenever appropriate.
Thus the word move operation `w'
will advance the cursor to the beginning of the next word in the
current input line, while the operation `3w' will advance three words.
.PP
.B "Interline operations."
Interline operations allow the introduction of new lines,
the movement of lines,
making copies of existing lines,
joining together text from several lines to form one new line,
substitution of new lines for old,
and the deletion of lines.
Most of these operations ignore the cursor position
within the current line.
It is also possible to introduce new lines into the file by inserting
text within a line and including a new-line character in this text.
This has the effect of ``splitting'' the line into two new lines.
.PP
.B "Open mode display."
In
.I open
mode,
the text of the current line is displayed with the cursor initially
at the first non-blank position of the line.
If a regular expression is given following the
.I open
command then the first character which matched this expression
is the character under the cursor.
The single displayed logical line usually occupies one physical line
on the screen but may,
on a cursor-addressible terminal,
occupy several lines.\u\s-2\(dg\s0\d
.FS
\(dg On cursor addressible terminals,
the second to the last line is used instead of the last line.
This avoids screen roll-up problems often associated with the
last column of the last line.
On terminals without cursor-addressing capability,
an error will occur if the line is too long to fit
on one physical screen line.
.FE
.PP
.B "Visual mode display."
In
.I visual
mode,
a number of logical lines are placed on the screen,
with long lines folded to occupy several physical lines.
The cursor may be moved between these
lines and each can be edited as with
.I open .
In addition,
the interline operations listed above may be conveniently performed
in
.I visual
mode.
.PP
.B "Empty lines."
Physical lines in the display which are not occupied by any portion of logical
lines are represented by the character `@' alone at the beginning of the line.
Physical lines past the end of file are displayed using the
character `~' instead of `@'.
.PP
.B "Cleaning up the screen."
If you have made a number of line changes, creating empty physical lines
displayed as `@', you may wish to maximize the information on the screen.
You can do this with the \s-2CTRL\s0(Z) operation.
.PP
.B "Operation errors."
If an operation formation or execution 
error occurs the terminal bell is rung and any partially
formed command is discarded.
The bell is also rung when a \s-2DELETE\s0
is used to cancel an operation and when an \s-2ESC\s0
is sent when no operation is in progress.
.PP
.B Escape.
The \s-2ESC\s0 escape character is extensively used in 
.I open
and
.I visual .
As we saw above, it is used to terminate text input.
It is also used to abort partially formed commands.
Thus `4\s-2ESC\s05x' will delete 5 characters; here
we changed our mind after typing a `4' and cancelled it
with \s-2ESC\s0 to start anew with a `5'.
If \s-2ESC\s0 is hit when there is no partially formed command in progress,
the editor will ring the bell to let you know that nothing is happening.
.PP
.B "Getting out."
To get out of
.I open
or
.I visual
you should use the
`q' quit operation.
If you hit two successive
\s-2DELETE\s0 (i.e. \s-2RUBOUT\s0) characters or a single
\s-2QUIT\s0 character,
you will also drop out of
.I open
or
.I visual .
.PP
.B "Bombing out."
If you find a bug in the editor, or if a problem occurs in the
system you may find the editor ungracefully terminating either
just an
.I open
or
.I visual
command or the entire session.
In this case, you may be left with the terminal in a funny state
so that keys do not echo when you hit them.
The thing to note in this situation is that your normal
erase character and kill line sequences
will, most likely, not work, and also
that the carriage return character may be different from the new-line character,
the former being, quite often, non-functional.
The way to recover from this is to type the command:\u\s-2\(dg\s0\d
.DS
.B "stty cooked echo \-nl"
.DE
.FS
\(dg If you are lucky, your system may have the
.I tset
command which performs this function without requiring any arguments.
Then all you will have to do is type `tset' followed by a new line
character, possibly preceded by a `!' if the editor is still with you.
.FE
If you are still talking to the editor you will have to put the
escape `!' in front of this command.
Note especially that you must type this command without mistakes,
and that you must terminate it with a newline.
(This entire operation may be difficult because you won't be getting
any echo from the system.)
If you make a mistake, just send the mangled line with a newline and start over.
If you stick a single, unmatched `\(aa' on the end of the line,
the shell will scream about the syntax error and not execute the
garbage you typed.
.PP
.B Sync.
If you have made a number of changes and wish to insure them against
a system crash, you can invoke the
.I sync
command from within
.I visual
or open
via the \s-2CTRL\s0(S) operation.
.br
.ne 30
.bp
.SH
Operation descriptions
.PP
.B "Scope of operation."
All changes in
.I open
or
.I visual
are limited in scope to the visible screen text.
Each single change may be reversed with the undo `u' operation.
In addition, a disastrous
.I open
or
.I visual
command may be completely undone at the command level.
.PP
.B "Format of the operations."
Most operations take an optional preceding count, given as a decimal
number (not starting with a digit `0').
A number of operations take a following
.I text
string which is inserted into the buffer as specified by the operation.
Some operations take a following operation,
called the targeting operation,
to indicate the scope on which they are to have effect.
This second ``targeting''
operation specifies the cursor motion for the first operation.
Thus a simple operation would be `x' deleting the (single) character
under the cursor.
We could delete two characters by specifying `2x' or `xx',
the former being preferred.
An example of an operation which takes targeting is delete `d',
thus `dw' will delete a word.
Finally, the insert operation is typified by `ifoo\s-2ESC\s0'
where here the text `foo' is inserted before the current
cursor position.
The character \s-2ESC\s0 here is used to terminate the text input.
.PP
.B "Definition of ``word''."
There are two different definitions of ``word'' used in
.I open
and
.I visual .
The primary definition is a sequence of letters, digits, and underscores,
or a sequence of other (non-white) characters followed by trailing white 
space (blanks and tabs).
This is the conservative definition of word.
The other, liberal, definition of a ``word'' treats it simply as a maximal
sequence of non-blanks with trailing white space.
There are two sets of word operations;
`w' and `b' are conservative, `W' and `B' liberal.
The back word \s-2CTRL\s0(W) operation in text insert mode is liberal;
it is especially useful for fast typists who want to quickly and accurately
back over several mangled input words.
.PP
.B "Intraline motion operations."
There are four basic kinds of intraline motion operations \-
those dealing with characters, those dealing with ``words'',
those dealing with targets (either single characters or specified
column positions), and, finally, special motions
e.g. to the beginning of,
first non-blank character of,
or end of a line.
The basic character oriented operations are \s-2SPACE\s0 advancing
one position to the right and \s-2CTRL\s0(H) a backspace which backs
up to the right.\u\s-2\(dg\s0\d
.FS
\(dg On the \s-2ADM-3A\s0 the control functions of the
keys `h', `j', `k', and `l' perform
the left, down, up, and right cursor motions respectively.
Hence, for convenience on this most commonly available terminal,
the operations `h', `j', `k' and `l' perform as their control-key
counterparts in repositioning the cursor.
Thus, in the present cases, `h' works as well as \s-2CTRL\s0(H),
and `l' is equivalent to \s-2SPACE\s0.
.FE
The basic word oriented operations are `w' moving forward to the beginning
of the next word, and `b' moving backward to the beginning of the preceding
word.
.PP
.B "Single character targets."
The character targeting operations are `f', `F', `t' and `T'.
Each takes a single following character and searches the current
line for that character.
The lower case operations search to the right,
the upper case operations to the left.
The `f' and `F' (find) operations are inclusive;
that is, they reference through to the specified characters.
The `t' and `T' (to) operations are not inclusive but rather move
the cursor up to the specified target.
.PP
.B "Special motions."
The special intraline motion sequences are `^' specifying the first
non-blank character on the line;
`$' specifying the last character on the line;
and `0' specifying the first position on the line.
Finally, there is an operation `|', used with a preceding count,
which references the column position specified by the count, much
as a `f' operation would.
.PP
.B "Operators and targeting operations."
Some operations are actually prefix operators,
taking another operation, called the targeting operation or
.I target
after them to indicate the scope on which they are to have effect.
There are four such operations \-
`c' change,
`d' delete,
`g' grab,
and
`y' yank.
The first two are by far the most important.
The targeting operation must be a intraline motion sequence.
Thus `c2w' could begin an operation changing the next two words
in the current line, while `dt)' would delete the text up to the next `)'
character in the current line.
.PP
.B "Interline motions."
The most primitive interline motion operations are those which
advance integral numbers of lines,
typified by a carriage return \s-2CR\s0 or new line \s-2NL\s0.
There are two kinds of such operations in each direction \-
the pure cursor motion operations which maintain the current column
position as much as possible, and the motion sequences which
advance to the first non-blank position of the target line.
.PP
Interline motions which respect the current column position include
`k' (also \s-2CTRL\s0(K) on an \s-2ADM-3A\s0) moving up a line,
and \s-2NL\s0 or `j' or \s-2CTRL\s0(J) moving down a line.
Motion sequences which place the cursor in the first non-blank position
are `+' or \s-2CR\s0 moving down, and `\-' moving up.
These motion sequences take counts thus `5\-' will move back five
lines.
There are also special sequences `H' for home which returns the cursor
to the first non-blank character of the first line on the screen,
and `L' to the first non-blank character of the last.
.PP
.B Insertion.
Text insertion is indicated by
.I text
in the operation descriptions below.
Pure text insertion is begun with the `i' or `a'
operations and continues to an \s-2ESC\s0.
If the first character of
.I text
is the null character,
generated by a \s-2CTRL\s0(@),
then the previous inserted text is re-used.
.I Text
may contain new-line characters
which cause the current line to be split and a new line to be
added to the buffer.
A number of control characters may be used to edit the inserted text
while inserting.
These include \s-2CTRL\s0(H) to back over a character,
\s-2CTRL\s0(W) to back over a word (liberal definition),
`@' to delete the (current line portion) of the input.
Also, the character \s-2CTRL\s0(X) is interchangeable with `@' here
and as an deleting operation.
To enter any of these special characters into the input line they must
be preceded by a `\e'.
This applies also to the \s-2DELETE\s0, \s-2QUIT\s0 and \s-2CTRL\s0(D)
characters.
The first two normally cause termination of the text insert;
\s-2CTRL\s0(D) is used as a backtab in
.I autoindent
and otherwise normally ignored.
.PP
Convenient intraline insertion abbreviations are `I' adding
text before the first non-blank of the current line, and
`A' adding text at the end of the line.
These are similar to the two character sequences `^i' and
`$a' respectively.
.PP
.B Deletion.
The deletion operator `d' may be placed before any intraline motion
sequence to form a deleting operation, deleting the moved
over text from the current line.
Thus `dw' will delete a word while `d40|' will delete to column 40.
Convenient deletion abbreviations are `x' deleting characters,
`X' deleting the specified number of preceding characters,
and `#', similar to `X' except that it deletes the character at the
cursor while `X' deletes the character before the cursor.
Finally there are the abbreviations `D' which deletes to the end of the
line, i.e. `d$', and `@' which deletes to the beginning of the line,
i.e. `d0'.
Note also that the operation \s-2CTRL\s0(X) is a synonym for `@'.
.PP
.B Change.
Similar to the delete operations are the change operations,
which are formed with `c' and any motion sequence.
The specified text is deleted, indicated by marking the right end of it
with a `$' character, and then the input up to an \s-2ESC\s0
replaces it.
Thus `cwfoo\s-2ESC\s0' will replace the current word with the word `foo'.
Useful abbreviated changes are `C' which changes the rest of the line,
i.e. `c$', and `s' which changes the number of characters
specified by the preceding count.
.PP
.B Replace.
There are two forms of the replace operation.
The first, `r', replaces the single character under the cursor with
the single following character (no terminating \s-2ESC\s0 is
required.)
The second form `R' replaces as many following characters as are typed
with the new input characters.
This operation is essentially an ``overstrike'' much as a normal terminal
display functions.
It is useful in editing pictures and other data where a fixed field
size is to be maintained.
.PP
.B "Interline inserts."
Some operations add a new line to the buffer.
These ignore the cursor position on the current line,
and do not split it, rather creating a new line.
The two operations of this type are `o' which adds a new line
after the current line and `O' which adds a new line before the current line.
In both cases, following text up to an \s-2ESC\s0 defines one or more
new lines.
A count may be usefully given before `o' or `O' indicating the number
of physical lines to be opened up.
If this is an estimate of the number of lines to be added it can help
to minimize the output required to redraw the screen on terminals
which are unintelligent.
Thus an appropriate beginning of a sequence to add three new lines
after the current line would be `3o'.
.PP
.B "Line deletes, joins."
Lines may be deleted from the buffer using the command `\e\e' (two backslashes)
or joined together using `J'.
A specified number of lines may be replaced with new text conveniently
using the line substitute operation `S'.
.PP
.B "Interline scans."
It is possible to scan between lines for text specified by a regular expression
and, in
.I visual ,
to specify where this line is to appear on the screen if it must be redrawn.
Forward scans are begun with `/' and backward scans with `?'.
After hitting `/' or `?' you enter the pattern you wish to scan for
and it is shown on the bottom line of the screen.
You can terminate the pattern either with an \s-2ESC\s0 or a \s-2CR\s0 or
\s-2NL\s0; to abort a partially formed
scanning operation you can type a \s-2DELETE\s0
or \s-2RUBOUT\s0 character.
If the search fails the bell is rung,
the scan delimiter `/' or `?' is replaced with a `F' indicating
a failed search,
and the cursor returns to its previous position with
typeahead discarded.
If the search succeeds then the cursor is placed at the beginning
of the string which matched.
The screen is redrawn with the line matched in the center
unless (in
.I visual
only)
a specific positioning request has been made by following the pattern
with `z' or `v' and then one of `\(ua', `-', `.', or a \s-2CR\s0 or \s-2NL\s0
specifing the top of the screen.
.PP
.B "Scrolling."
The operation \s-2CTRL\s0(D) may be used, as in command mode,
to effect a scroll.
The number of lines to be scrolled may be specified by a preceding count;
this count will hold for succeeding
.I open
and
.I visual
scrolls until respecified.
.PP
.B "Context displays."
Sequences `z\fItype\fR' and `v\fItype\fR'
may be equivalently used to specify context display as in command mode.
In
.I open
mode the
.I type
is not required and a command mode like `z=' command is always done.
In
.I visual
.I type
may be any of `\(ua', `-', `\fB.\fR' or \s-2CR\s0 or \s-2NL\s0
specifying the top of the screen.
.PP
.B Memory.
The editor remembers the last
.I visual
or
.I open
command and associated data in each of several categories
and allows it to be respecified by a very short, one character sequence.
.IP
.B "Last single character scan."
The last of the targeting operations
.I f ,
.I F ,
.I t ,
and
.I T
is remembered with the character supplied to it.
This combination is used again through the operation `;'.
.IP
.B "Last interline scan."
The last of the interline scans using `/' or `?' is remembered and may
be repeated with the operation
.I n
(next.) 
.IP
.B "Last modifying command."
The last command which modified the buffer is remembered
and may be repeated by the command form `\fB.\fR'.
.IP
.B "Last inserted text."
The text which was last inserted (up to 128 characters) is remembered
and may be specified in future operation by a null character, generated
by a \s-2CTRL\s0(@).
This is given when
.I text
would begin,
instead of
.I text.
The
\s-2ESC\s0
terminating the
.I text
is not needed.
If there is no previous inserted text, or if the previous inserted
text was longer than 128 characters, the bell is rung and the operation
completes inserting no text.
If the aborted operation was a scan via `/' or `?', then it aborts
as though it had been cancelled with a \s-2DELETE\s0 character.
.IP
.B "Last deleted text."
The last deleted text which was part of a single line (up to 128
characters) is remembered.
If the last thing deleted was one or more lines, then this will
be remembered instead.
There are put operations `p' and `P' which allow this deleted
text to be returned to the buffer.
Note that a number of operations set both
the deleted and inserted text (notably change operations.)
.sp
.PP
.B "Grab, yank, and put."
There are two related operators yank `y' and grab `g' which take
a motion sequence target and pretend it was the previous inserted or
deleted text respectively.
The grab `g' operation is especially useful when you wish
to search for something on the screen \-
you can grab it, e.g. if it is a word with `gw',
and then do a scan defaulting the search with a null character, i.e.:
`/\s-2CTRL\s0(@)'.
There are also operations `p' and `P' which put text which was deleted
back into the buffer.
If the previous deletion was of lines, then these operations will add
new lines with the same text after or before the current line respectively.
Similarly if the previous deletion was a part of a line,
then the text will be put after/before the cursor position in the current line.
There is also an operation `Y' which yanks a specified number of lines
as though they had been deleted but does not delete them.
This can be used to copy lines.
As an example, the sequence `Yp' places a copy of the current line after the current line.
.PP
.B "Interline motions."
The are a number of interline motion sequences dealing with the mark
registers and specific line numbers.
The operation `G' causes the line specified by the preceding count
to become the current line.
If this line is on the screen, then the screen is not redrawn.
The default line for `G' if no count is given is the last line of the file.
Thus `G' is the easiest way to get to the end of the file.
.PP
The sequences `\(aa\fIx\fR' where \fIx\fR is a single lower case letter
cause the display to return to the specified marked line, with the
marked line in the center.
The previous context mark `\(aa\(aa' may also be requested here,
and it is set by the searching operations `/' and `?',
the `G' operation,
the mark operations `\(aa\fIx\fR',
and the
`v' or `z' operations when a count is given.
Marks may be set while in
.I visual
or
.I open
by using the
.I K
operation and following it by a single lower case letter specifying the
register to be marked.
.SH
Miscellaneous notes on visual and open
.PP
The options
.I beautify
and
.I indicateul
are suppressed in
.I open
and
.I visual .
All the features of
.I autoindent
are available.
If the cursor is at a tab character in the line which is represented by
a number of blanks,
it is placed at the last blank.
Lines yanked with `Y' or deleted with `\e\e' may be
put with `p' or `P' in a later
.I visual
or
.I open
command only so long as no
.I edit
or
.I next
command
intervenes.
It is not possible to
.I undo
an appending operation in
.I open
or
.I visual
which resulted in the creation of more than a screen full of lines.
An operation affecting only the text within a single line is undoable only
while the cursor remains on that line.
.bp