Content-type: text/html
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]
The
edit
command provides a line editor designed
for beginning users.
Indents appropriately for LISP code, and accepts the
(,
),
{,
},
[, and
]
characters (parentheses, braces, and
brackets) as text rather than interpreting them as
vi
subcommands.
The LISP modifier is active in
open
or
visual
modes.
Recovers
file
after an editor or
system crash. If you do not specify
file, a list
of all saved files is displayed.
Sets the
readonly
option, preventing you
from altering the file.
Loads the file that contains
tag
and positions the editor at
tag. To use this option,
you must first create a database of function names and locations using the
ctags
command.
Invokes the
visual
editor. When the
-v
option is specified, an enlarged set of subcommands are available,
including screen editing and cursor movement features. See
vi.
Sets the default window size to
number
lines.
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.
When
subcommand
is not entered, a + (plus sign)
sets the current line to the bottom of the file. Normally
edit
sets the current line to the last line of the file, or to some specified tag
or pattern.
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.
The
edit
command does not make changes to the file
until you use the
w
subcommand to write the changes.
The
edit
command operates in one of two modes:
In command mode, the
edit
editor recognizes
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
a,
c,
or
i
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
<Return>. Press
<Ctrl-d>
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.
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
^
(circumflex),
$
(dollar sign), and
\
(backslash) have special
meanings as pattern-matching characters; however, several additional characters
also have special meanings in
ex.
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.
The
edit
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
a
subcommand appends text after the addressed line. If you specify address
0 (zero), the
a
subcommand places the text at the beginning
of the buffer. As you type your text, press
<Return>
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
a
to
z,
edit
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.
address1
and
address2
are optional;
you must specify
address3.
Places the specified line or lines in
buffer
(identified by a single alpha character name
a
to
z).
Retrieves the contents of the specified buffer and places
it after
address. 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.
Ends the editing session. The
quit
command
does
not
write the editor buffer to a file; 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.
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 filename. If
file
does not exist,
edit
creates it.
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.
Recovers
file
from the system save
area. Use this after a system crash, or a
preserve
subcommand.
Replaces on each specified line the first instance of
pattern
with the replacement pattern
replacement. If you add the global indicator
g, it
replaces all instances of
pattern
on each specified
line.
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
subcommand.