Provides a simple line editor for the new user.
edit [ -r ] [ File ... ]
The edit command starts a line editor designed for beginning users, a simplified version of the ex editor. The edit editor belongs to a family of editors that includes the ed editor, ex editor, and vi editor. Knowing about the edit editor can help you learn the more advanced features of the other editors. To edit the contents of a file, enter:
edit File
When the file specified by the File parameter names an existing file, the edit command copies it to a buffer and displays the number of lines and characters in it. It then displays a : (colon) prompt to show that it is ready to read subcommands from standard input.
If the file specified in the File parameter does not already exist, the edit command indicates this information and creates the new file. You can specify more than one file name for the File parameter, in which case the edit command copies the first file into its buffer and stores the remaining file names in an argument list for later use. The edit editor does not make changes to the edited file until you use the w subcommand to write the changes.
The edit editor operates in one of
the following two modes:
command mode | Recognizes and runs the edit editor subcommands. When you start the edit editor, it is in command mode. To enter command mode at other times, enter only a . (period) at the beginning of a line. |
text input mode | Allows you to enter text into the edit editor buffer. Enter text input mode by using the append (a) subcommand, change (c) subcommand, or insert (i) subcommand. To end text input mode, enter only a . (period) at the beginning of a line. |
-r | Recovers the file being edited after an editor or system malfunction. |
The edit editor uses the following three types of addresses:
Line number addresses specify a line within a file by its line number or symbolic name. This method is the simplest way to address a line or lines.
To address the first line by its symbolic name, enter:
.
To address the last line by its symbolic name, enter:
$
You also can specify a range of lines by separating the line numbers or symbolic addresses with a comma or a semicolon. The second address must refer to a line that follows the first addressed line in the range.
1,5
addresses the lines 1 through 5.
.,$
addresses the first through the last lines.
The edit editor can address a line by its relative position to the current line. An address that begins with the -Number or +Number parameter addresses a line the specified number of lines before or after the current line, respectively.
+8
addresses 8 lines after the current line.
You can also address a line relative to the first or last line by using the symbolic names in combination with the -Number or +Number addresses.
.+3
addresses 3 lines after the first line, and:
$-10
addresses 10 lines before the last line.
You can specify an address line by searching the buffer for a particular pattern. The edit editor searches forward or backward and stops at the first line that contains the match for the Pattern parameter. If necessary, the search wraps past the end or beginning of the buffer until it finds a match or returns to the current line.
/Pattern/
?Pattern?
You also can specify a range of lines by separating the Pattern parameters with a comma or a semicolon. The second address must refer to a line that follows the first addressed line in the range.
Pattern,Pattern
The following characters have
special meanings when used as part of the Pattern parameter:
^ | Matches the beginning of a line when used as the first character of the Pattern parameter. |
$ | Matches the end of a line when used as the last character of the Pattern parameter. |
The edit editor subcommands affect the current line, which is represented by a . (period). When you start the edit editor, the current line is the last line in the buffer. As the buffer is edited, the current line changes to the last line affected by a subcommand. To work with different parts of a file, you must know how to find the current line and how to address different lines in a file.
You can use the edit editor subcommands to perform the following tasks:
In the following subcommands, the
Address parameter is optional. If you specify an address, do
not type the brackets. You can use the full subcommand or its
abbreviation, which is shown in parentheses.
Appends the text you type after the current line if you do not specify an
Address parameter. You may need to find
the current line or specify an address if you are
not in the correct position in the buffer.
If you specify an address, the a subcommand appends text after the specified line. If you specify a 0 address, the a subcommand places the text at the beginning of the buffer. Type the text, pressing the Enter key at the end of each line. When you have entered all the text, type a . (period) alone at the start of a line to end text input mode and return to command mode. You can use the 1,$p subcommand to display the entire contents of the buffer.
Note: The a subcommand differs from the i subcommand in the placement of text. | |
Inserts text before the current line if you do not specify an
Address parameter. You may need to find
the current line or specify an address if you are
not in the correct position in the buffer.
If you specify an address, the i subcommand inserts text before the specified line. You cannot specify a 0 address. Type your text, pressing the Enter key at the end of each line. When you have entered all your text, type a . (period) alone at the start of a line to end text input mode and return to command mode. You can use the 1,$p subcommand to display the entire contents of the buffer.
Note: The i subcommand differs from the a subcommand in the placement of text. |
file File | Changes the name of the current file to the name specified by the File parameter. The edit editor does not consider this file to be edited. |
In the following subcommand, the
Address parameters are optional. If you specify an address,
do not type the brackets. You can use the full subcommand or its
abbreviation, which is shown in parentheses.
Replaces the current line with the text you type if you do not specify
the Address parameters. You may need to find the current line or specify an
address if you are not in the correct position in the buffer.
If you specify an address, the c subcommand replaces the addressed line or lines. You can specify a range of lines by separating the addresses with a comma. Type your text, pressing the Enter key at the end of each line. When you have entered all your text, type a . (period) alone at the start of a line to end text input mode and return to command mode. You can use the 1,$p subcommand to display the entire contents of the buffer. The last input line becomes the current line. |
In the following subcommand, the
Address and Buffer parameters are optional. If
you specify an address or buffer, do not type the brackets. You can use
the full subcommand or its abbreviation, which is shown in parentheses.
[Address1,Address2] delete [Buffer] (d) | Deletes the current line if you do not specify the Address
parameters. You may need to find the current
line or specify an address if you are not in the
correct position in the buffer.
If you specify an address, the d subcommand deletes the addressed line or lines. You can specify a range of lines by separating the addresses with a comma. The line following the last deleted line becomes the current line. If you specify a buffer by giving a lowercase letter from a to z, the edit editor saves the addressed lines in that buffer. If you specify an uppercase letter, the ed editor appends the lines to that buffer. You can use the pu subcommand to put the deleted lines back into the buffer. |
In the following subcommand, you
can use the full subcommand or its abbreviation, which is shown in
parentheses.
file (f) | Displays the current file name along with the following related
information:
|
In the following subcommands, the
Address parameters are optional. If you specify an address,
do not type the brackets. You can use either the full subcommand or its
abbreviation, which is shown in parentheses.
In the following subcommand, you
can use the full subcommand or its abbreviation, which is shown in
parentheses.
edit File (e) | Begins an editing session on a new file specified by the File
parameter. The editor first checks to see if the buffer was edited
since the last write (w)
subcommand.
If the file was edited since the last w subcommand, the edit editor issues a warning and cancels the e subcommand. Otherwise, the edit editor deletes the 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, the edit editor reads the file into its buffer. If the edit editor 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. |
next (n) | Copies the next file named in the command line argument list to the buffer for editing. |
In the following subcommands, you
can use the full subcommand or its abbreviation, which is shown in
parentheses.
quit (q) | Ends the editing session after using the write (w) subcommand. If you have modified the buffer and have not written the changes, the edit editor displays a warning message and does not end the editing session. |
quit! (q!) | Ends the editing session, discarding any changes made to the buffer since the last w subcommand. |
In the following subcommand, the
Address parameters are optional. If you specify an address,
do not type the brackets. You can use the full subcommand or its
abbreviation, which is shown in parentheses.
[Address1,Address2]global/Pattern/SubcommandList (g) | Marks each of the addressed lines that match the Pattern
parameter. The edit editor then performs the list of subcommands
specified in the SubcommandList parameter on each marked
line.
If you do not specify the Address parameters, the g subcommand works on the current line. You may need to find the current line or specify an address if you are not in the correct position in the buffer. If you specify an address, the g subcommand works on the addressed line or lines. You can specify a range of lines by separating the addresses with a comma. A single subcommand or the first subcommand in a subcommand list appears on same line as the g subcommand. The remaining subcommands must appear on separate lines, where each line (except the last) ends with a \ (backslash). The default subcommand is the print (p) subcommand. The subcommand list can include the append (a) subcommand, insert (i) subcommand, and change (c) subcommand, and their associated input. In this case, if the ending period is on the last line of the command list, you can omit it.
Note: The undo (u) subcommand and the g subcommand cannot appear in the subcommand list. |
In the following subcommands, the
Address1 and Address2 parameters are optional. If
you specify an address, do not type the brackets. You must specify the
Address3 parameter. You can use either the full subcommand
or its abbreviation, which is shown in parentheses.
[Address1,Address2]move Address3 (m) | Moves the current line after the line specified by the
Address3 parameter if you do not specify an address or an address
range. You may need to find the current line
or specify an address if you are not in the correct
position in the buffer.
If you specify an address, the m subcommand moves the addressed line or lines. You can specify a range of addresses by separating the addresses with a comma. The first of the moved lines becomes the current line. |
[Address1,Address2]yank [Buffer] (ya) | Copies the specified line or lines into the Buffer, an optional parameter specified by a single alpha character a to z. You can use the pu subcommand to put these lines into another file. |
[Address]put [Buffer] (pu) | Retrieves the contents of the specified Buffer parameter and
places it after the current line if you do not specify an address. You
may need to find the current line or specify an address if you are not in the correct position
in the buffer.
If you specify an address, the pu subcommand retrieves the contents of the specified buffer and places it after the addressed line. If you do not specify a Buffer parameter, the pu subcommand restores the last deleted or copied text. You can use the pu subcommand with the delete (d) subcommand to move lines within a file or with the yank (ya) subcommand to duplicate lines between files. |
preserve | Saves the current editor buffer as though the system had just malfunctioned. Use this subcommand when a write (w) subcommand has resulted in an error and you do not know how to save your work. Use the recover subcommand to recover the file. |
recover File | Recovers the file specified by the File parameter from the system save area. Use this subcommand after a system crash or after a preserve subcommand. |
In the following subcommand, the
Address parameters are optional. If you specify an address,
do not type the brackets. You can use the full subcommand or its
abbreviation, which is shown in parentheses.
In the following subcommand, the
Address parameters are optional. If you specify an address,
do not type the brackets. You can use either the full subcommand or its
abbreviation, which is shown in parentheses.
| |
[Address1,Address2] substitute/Pattern/Replacement/g | Replaces the first instance of the specified Pattern parameter
on each addressed line. You can replace every instance of the
Pattern parameter by adding the global
(g) subcommand to the end of the s subcommand.
If you do not specify an address, the s subcommand works on the current line. You may need to find the current line or specify an address if you are not in the correct position in the buffer. If you specify an address, the s subcommand works on the addressed line or lines. You can specify a range of lines by separating the addresses with a comma. |
In the following subcommand, you
can use the full subcommand or its abbreviation, which is shown in
parentheses.
undo (u) | Reverses the changes made in the buffer by the last buffer editing
subcommand. You cannot undo a write
(w) subcommand or an edit (e)
subcommand.
Note: The global subcommands are considered a single subcommand to a u subcommand. |
The ed or red command, ex command, vi or vedit command.