edit
PURPOSE
Provides a simple line editor for the new user.
SYNOPSIS
edit [ -r ] names
DESCRIPTION
Warning: The edit command does not support international
characters. If you use this command to edit a file that
contains extended characters, you can lose data.
The edit command provides a line editor designed for
beginning users. It is a simplified version of the ex
command (see "ex"). To edit the contents of a file,
enter:
"edit" file
If file is the name of an existing file, edit copies it
to a buffer and displays the number of lines and charac-
ters in it. Then it displays a colon prompt (":") to
show that it is ready to read subcommands from standard
input. If file does not already exist, edit tells you
this, but still stores the name as the current file name.
You can give more than one file name, in which case edit
copies the first file into its buffer and stores the
remaining file names in an argument list for later use.
The edit command operates in one of two modes: command
mode and text entry mode. In command mode, edit displays
the colon prompt to show you that it is ready to accept
edit subcommands. In text entry mode, edit places all
input into its editing buffer. The general format of an
edit subcommand is as follows:
[addr]subcommand [parameters] [count]
If you do not specify an address, edit works on the
current line. If you add a numeric count to most subcom-
mands, edit works on the specified number of lines.
For most subcommands, the last line affected becomes the
new current line. That means, for example, that after
edit reads a file into its buffer, the last line in the
file becomes the current line. addr can be a line number
or a pattern to be matched or, in some cases, a range of
line numbers or patterns. To specify a range, separate
two line numbers or patterns with a comma or a semicolon
(for example, "1,5" or "1;5"). In a range, the second
address must refer to a line that follows the first
addressed line in the range.
ADDRESSING LINES WITHIN A FILE
The simplest way to address a line within a file is to
use its line number. But this can be unreliable because
line numbers change when you insert and delete lines.
edit provides a way to search through the buffer for
strings. Given the following address:
/pattern/
edit searches forward for pattern, while given:
?pattern?
it searches backwards for pattern. If a forward search
reaches the end of the buffer without finding pattern, it
continues the search at the beginning of the file until
it reaches the current line. A backwards search does
just the reverse.
The following characters have special meanings in these
search patterns:
^ Matches the beginning of a line.
$ Matches the end of a line.
Thus, you can use /^pattern/ to search for patterns at
the beginning of a line, and /pattern$/ to search for
patterns at the end of the line.
The current line has a symbolic name, dot ("."), and the
last line in the buffer has a symbolic name, dollar sign
("$"), that you can use in addresses. This is useful
when working with a range of lines. For example,
.,$print
displays all lines from the current line to the last line
in the buffer. Arithmetic with line references is also
possible, so that "$-5" refers to the fifth line from the
last and ".+20" refers to the line 20 lines past the
current line. You can also use the = (equal) command to
find out the line number of the current line or the last
line, as follows:
.=
$=
To view the next line in the buffer, press the Enter key.
Press Ctrl-D to display the next half-screen of lines.
Note: Do not confuse the meaning of "$" in text patterns
(end of line) with its meaning in addresses (last line).
USING A FAMILY OF EDITORS
The edit command is part of a family of editors that
includes edit, ex, and vi. The edit command is a simple
line editor designed for beginning users. It is a sim-
plified version of ex. After you become more experienced
with edit, you may want to try the advanced features of
one of the other editors in the family. Because edit is
part of a family of editors, you can apply your knowledge
of edit to the other editors in the family.
The ex editor is a powerful interactive line editor. The
edit subcommands work the same way in ex, but the editing
environment is somewhat different. For example in edit,
only the characters ^, "$", and \ have special meanings
as pattern-matching characters; however, several addi-
tional characters also have special meanings in ex. For
more information on ex, see "ex."
The vi editor is a display-based editor designed for
experienced users that do a lot of editing at their
display. It contains many of the advanced features of
ex, but focuses on the display editing portion of ex.
The edit editor prevents you from accidentally entering
vi's two alternative modes of editing, the open mode and
the visual mode. For more information on vi, see "vi,
vedit, view."
FLAG
-r Recovers file after an editor or system crash.
SUBCOMMANDS
You can enter most edit subcommands as either a complete
word or an abbreviation. In the following list, a sub-
command abbreviation appears in parentheses. Unless
noted otherwise, all subcommands work by default on the
current line. edit recognizes and interprets the fol-
lowing subcommands when it displays the colon prompt:
[addr]append (a)
text
. Reads the input text into the file being
edited, placing the text after the line at
the specified address. If you specify
address 0, edit places the text at the begin-
ning of the buffer. To return to command
mode, enter a line with only only a .
(period) in the first position.
[addr1[,addr2]]change (c)
text
. Replaces the specified line or lines with the
input text. If any lines are input, the last
input line becomes the new current line.
[addr1[,addr2]]delete [buffer] (d)
Removes the specified line or lines from the
editing buffer. The line following the last
deleted line becomes the current line. If
you specify a buffer by giving a letter from
"a" to "z", edit saves the specified lines in
that buffer or, if the letter is uppercase,
appends the lines to that buffer.
edit file (e) Begins an editing session on a new
file. The editor first checks to see if the
buffer has been modified (edited) since the
last write subcommand. If it has, edit
issues a warning and cancels the edit subcom-
mand. Otherwise, it deletes the complete
contents of the editor buffer, makes the
named file the current file, and displays the
new file name. After insuring that this file
can be edited, it reads the file into its
buffer. If edit reads the file without
error, it displays the number of lines and
characters that it read. The last line read
becomes the new current line.
file (f) Displays the current file name along with the
following information about it:
o Whether it has been modified since the
last write.
o What the current line is.
o How many lines are in the buffer.
o What percentage of the way through the
buffer the current line is.
file file Changes the name of the current file to file.
edit considers this file not edited.
[addr1[,addr2]]global/pattern/cmds (g)
Marks each of the specified lines that
matches the pattern. Then edit carries out
the specified subcommands (cmds) on each
marked line.
A single cmd or the first cmd in a subcommand
list appears on same line as global. The
remaining cmds must appear on separate lines,
where each line (except the last) ends with a
\ (backslash). The default subcommand is
print.
The list can include the append, insert, and
change subcommands and their associated
input. In this case, if the ending period
comes on the last line of the command list,
you may omit it. The undo subcommand and the
global subcommand itself, however, may not
appear in the command list.
[addr]insert (i)
text
. Places the given text before the specified
line. The last line input becomes the
current line. Otherwise, the current line
does not change.
[addr1[,addr2]]move addr3 (m)
Repositions the specified line or lines to
follow addr3. The first of the moved lines
becomes the current line.
next (n) Copies the next file in the command line
argument list to the buffer for editing.
[addr1[,addr2]]number (nu)
Displays each specified line or lines pre-
ceded by its buffer line number. The last
line displayed becomes the current line.
preserve
Saves the current editor buffer as though the
system had just crashed. Use this command
when a write subcommand has resulted in an
error, and you do not know how to save your
work.
[addr1[,addr2]]print (p)
Displays the specified line or lines. The
last line becomes the current line.
[addr]put buffer (pu)
Retrieves the contents of the specified
buffer and places it after addr. If you do
not specify a buffer, edit restores the last
deleted or yanked text. Thus you can use
this subcommand together with delete to move
lines or with yank to duplicate lines between
files.
quit (q)
quit! (q!) Ends the editing session.
Note: The quit command does not write the
editor buffer to a file. However, if you
have modified the contents of the buffer
since the last write, edit displays a warning
message and does not end the session. In
this case, either use the quit! subcommand to
discard the buffer or write the buffer and
then quit.
recover file Recovers file from the system save area.
Use this after a system crash, or a preserve
subcommand.
[addr1[,addr2]]substitute/pattern/repl/ (s)
[addr1[,addr2]]substitute/pattern/repl/g
Replaces on each specified line the first
instance of pattern with the replacement
pattern repl. If you add the g flag, it
replaces all instances of pattern on each
specified line.
undo (u) Reverses the changes made in the buffer by
the last buffer editing subcommand. Note
that global subcommands are considered a
single subcommand to an undo. You cannot
undo a write or an edit.
[addr1,[addr2]]write file (w)
Writes the contents of the specified line or
lines to file. The default range is all
lines in the buffer. edit displays the
number of lines and characters that it
writes. If you do not specify a file, edit
uses the current file name. If file does not
exist, edit creates it.
[addr1,[addr2]]yank [buffer] (ya)
Places the specified line or lines in buffer
(a single alpha character name a - z).
[addr]z Displays a screen of text, beginning with the
specified line.
[addr]z- Displays a screen of text, with the specified
line at the bottom of the screen.
[addr]z. Displays a screen of text, with the specified
line in the middle of the screen.
RELATED INFORMATION
The following commands: "ed," "ex," and "vi, vedit,
view."