Provides a simple line editor for the new user.
edit [ -r ] [ File ... ]
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:
Item | Description |
---|---|
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. |
Item | Description |
---|---|
-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
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.
.
$
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 first through the last lines.
Relative Position Addresses
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
$-10
addresses 10 lines before the last line.
Pattern Addresses
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:
Item | Description |
---|---|
^ | 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:
Adding Text
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.
Item | Description |
---|---|
[Address]append (a) Text . |
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.
|
[Address]insert (i)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.
|
Changing the Name of the Current File
Item | Description |
---|---|
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. |
Changing Text
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.
Item | Description |
---|---|
[Address1,Address2]change (c). Text |
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. |
Deleting Text
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.
Item | Description |
---|---|
[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. |
Displaying the Current File Name and Status
In the following subcommand, you can use the full subcommand or its abbreviation, which is shown in parentheses.
Item | Description |
---|---|
file (f) | Displays the current file name along with the following related
information:
|
Displaying Text and Finding the Current Line
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.
Item | Description |
---|---|
[Address1,Address2]number (nu) | Displays the addressed line or lines preceded
by its buffer line number. If you do not specify the Address parameters,
the nu subcommand displays the current line and number. If you specify an address, the nu subcommand displays the addressed line or lines. You can specify a range of lines by separating the addresses with a comma. The last line displayed becomes the current line. |
[Address1,Address2]print (p) | Displays the addressed line or lines. If you
do not specify the Address parameters, the p subcommand
displays the current line. If you specify an address, the p subcommand displays the addressed line or lines. You can specify a range of lines by separating the addresses with a comma. The last line displayed becomes the current line. |
[Address]= | Displays the line number of the addressed line. If you do not specify an Address parameter, the = subcommand displays the line number of the current line. |
[Address]z | Displays a screen of text beginning with the addressed line. If an Address parameter is not specified, the z subcommand displays a screen of text beginning with the current line. |
[Address]z- | Displays a screen of text with the addressed line at the bottom. If an Address parameter is not specified, the z- subcommand displays a screen of text with the current line at the bottom. |
[Address]z. | Displays a screen of text with the addressed line in the middle. If an Address parameter is not specified, the z. subcommand displays a screen of text with the current line in the middle. |
Editing Additional Files
In the following subcommand, you can use the full subcommand or its abbreviation, which is shown in parentheses.
Item | Description |
---|---|
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. |
Ending and Exiting the edit Editor
In the following subcommands, you can use the full subcommand or its abbreviation, which is shown in parentheses.
Item | Description |
---|---|
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. |
Making Global Changes
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.
Item | Description |
---|---|
[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.
|
Moving or Copying Text
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.
Item | Description |
---|---|
[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. You cannot use the pu and ya subcommands inside a macro. |
Saving a File after a System Malfunction
Item | Description |
---|---|
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. |
Saving Text
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.
Item | Description |
---|---|
[Address1,Address2]write [File] (w) | Writes the entire contents of the buffer to
the file specified by the File parameter if you do not specify
an address. If you specify an address, the w subcommand writes the addressed line or lines to the file specified. You can specify a range of lines by separating the addresses with a comma. The edit editor displays the number of lines and characters that it writes. If you do not specify a file, the edit editor uses the current file name. If a File parameter does not exist, the editor creates one. |
Substituting Text
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.
Item | Description |
---|---|
[Address1,Address2] substitute/Pattern/Replacement/ (s) [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. |
Undoing a Change
In the following subcommand, you can use the full subcommand or its abbreviation, which is shown in parentheses.