edit - Edits a file line by line with a simplified command set
edit [-c subcommand] [-lRv] [-wnumber] [+subcommand] [-] [file...]
edit [-c subcommand] [-lRv] [-t tag] [file...]
edit [-c subcommand] -r[file] [-lRv] [file]
command provides a line editor designed
for beginning users.
Indents appropriately for LISP code, and accepts the
characters (parentheses, braces, and
brackets) as text rather than interpreting them as
The LISP modifier is active in
after an editor or
system crash. If you do not specify
file, a list
of all saved files is displayed.
option, preventing you
from altering the file.
Loads the file that contains
and positions the editor at
tag. To use this option,
you must first create a database of function names and locations using the
editor. When the
option is specified, an enlarged set of subcommands are available,
including screen editing and cursor movement features. See
Sets the default window size to
Suppresses all interactive user feedback. If you use this
option, file input/output errors do not generate an error message.
Begins the edit with the specified editor search or subcommand.
is not entered, a + (plus sign)
sets the current line to the bottom of the file. Normally
sets the current line to the last line of the file, or to some specified tag
The edit command is part of a family of editors that also includes ed, ex, and vi. It is a simplified version of the ex editor, which itself is built on the ed line editor.
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 characters 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. You can give more than one file, in which case edit copies the first file into its buffer and stores the remaining filenames in an argument list for later use.
command does not make changes to the file
until you use the
subcommand to write the changes.
command operates in one of two modes:
In command mode, the
and executes subcommands. When you start the editor, it is in command mode.
In text input mode, you can add text to the editing buffer.
You enter text input mode by using the
subcommand. To exit text input mode (and return to
command mode), you enter a
(dot) alone at the beginning
of a line.
The general format of an edit subcommand is as follows: [address]subcommand[argument ...][count]
If you do not specify an address, edit works on the current line. When you start the edit program, the current line is the last line in the buffer. As you edit the buffer, the current line changes to the last line affected by a subcommand. (When edit reads a file into its buffer, the last line affected by the process of reading is the last line in the file.) If you add a numeric count to most subcommands, edit works on the specified number of lines.
The value for address 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.
To work with different parts of a file, you must know how to find out
the current line and how to address different lines in 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. The edit command provides a way to search through the buffer for strings. Given the following address, edit searches forward for pattern: /pattern/
If given the following address, edit searches backward for pattern: ?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 backward 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. Lines can be addressed by their line numbers; for example, 11 refers to line 11 of the buffer. In addition, the current line is addressed with a . (dot) and the last line in the buffer is addressed with a $ (dollar sign). This is useful when working with a range of lines. For example, the following command displays all lines from the current line to the last line in the buffer: .,$print
Do not confuse the meaning of $ in text patterns, end of line, with its meaning in addresses, last line. 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 sign) 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
to display the
next half-screen of lines.
As you become more experienced with edit, you might 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.
editor is a powerful interactive line editor.
subcommands work the same way in
but the editing environment is somewhat different. For example in
edit, only the characters
(dollar sign), and
(backslash) have special
meanings as pattern-matching characters; however, several additional characters
also have special meanings in
Unless otherwise noted, all subcommands work by default on the current line; address is optional. You can use the full subcommand or its abbreviation. Subcommand abbreviations appear after the command in the sections that follow.
You can use the 1,$p subcommand to display the entire contents of the buffer.
program recognizes and interprets the following
subcommands when it displays the colon prompt.
Appends the text you type after the current line, if you do
not specify an address. If you specify an address, the
subcommand appends text after the addressed line. If you specify address
0 (zero), the
subcommand places the text at the beginning
of the buffer. As you type your text, press
at the end of each line. When you have entered all your text, enter a
(dot) alone at the start of a line. This ends text input mode
and returns to command mode.
Places the given text before the specified line. Enter a
(dot) to return to command mode. The last line input becomes
the current line.
Replaces the current line or addressed line or lines with
the input text. Enter a
(dot) to return to command mode.
If any lines are input, the last input line becomes the new current line.
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
saves the specified lines in that buffer
or, if the letter is uppercase, appends the lines to that buffer.
Displays the current filename along with the following information: Whether it was modified since the last write. What the current line is. How many lines are in the buffer. What percentage of the way through the buffer the current line is.
Begins an editing session on a new file. The editor first checks to see if the buffer was modified since the last write subcommand. If it has, edit issues a warning and cancels the edit subcommand. Otherwise, it deletes the complete contents of the editor buffer, makes the named file the current file, and displays the new filename. After ensuring 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. Copies the next file in the command line argument list to the buffer for editing.
Marks each of the specified lines that matches the pattern, then carries out the specified subcommands (commands) on each marked line.
Repositions the specified line or lines to follow
address3. The first of the moved lines becomes the current line.
you must specify
Places the specified line or lines in
(identified by a single alpha character name
Retrieves the contents of the specified buffer and places
address. If you do not specify a buffer,
restores the last deleted or yanked text. Thus, you can use
this subcommand together with
to move lines or with
to duplicate lines between files.
Ends the editing session. The
write the editor buffer to a file; if
you have modified the contents of the buffer since the last
displays a warning message and does not
end the session. In this case, either use the
to discard the buffer or
the buffer and then
Writes the contents of the specified line or lines to
file. The default range is all lines in the buffer.
displays the number of lines and characters that it writes.
If you do not specify a
uses the current filename. If
does not exist,
Saves the current editor buffer as though the system had just
crashed. Use this command when a
resulted in an error, and you do not know how to save your work.
from the system save
area. Use this after a system crash, or a
Replaces on each specified line the first instance of
with the replacement pattern
replacement. If you add the global indicator
replaces all instances of
on each specified
Reverses the changes made in the buffer by the last buffer
editing subcommand. Note that
subcommands are considered
a single subcommand to an
undo. You cannot undo a
Commands: ed(1), ex(1), vi(1)