Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

edit(1) [osf1 man page]

edit(1) 						      General Commands Manual							   edit(1)

NAME
edit - Edits a file line by line with a simplified command set SYNOPSIS
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. OPTIONS
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. DESCRIPTION
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 dis- plays 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. Editing Modes 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. Subcommand Syntax 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. 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. 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 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. Using a Family of Editors 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. SUBCOMMANDS
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. Adding Text 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 com- mand mode. The last line input becomes the current line. Changing Text 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. Deleting Text 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. Displaying Text and Determining the Current Line 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. Also, sets the current filename if file is specified. Displays each specified line or lines preceded by its buffer line number. The last line displayed becomes the current line. Displays the specified line or lines. The last line displayed becomes the cur- rent line. Displays the line number of the addressed line. If you do not specify an address, displays the line number of the last line. Displays a screen of text, beginning with the current or specified line. Displays a screen of text, with the specified (or current) line at the bottom of the screen. Displays a screen of text, with the specified (or current) line in the middle of the screen. Editing Another File 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 buf- fer. 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. You can edit a sequence or group of files. You can use the next subcommand to edit each file on the command line in turn, or to specify a list of filenames to edit (using the shell pattern matching syntax) instead. The wildcard character % represents the name of the current edit file and can be used to form filenames. If file is specified, the command line argument list is replaced, and an edit command is performed on the first file. Making Global Changes Marks each of the specified lines that matches the pattern, then carries out the specified subcommands (commands) on each marked line. A single command or the first command in a subcommand list appears on the same line as global. The remaining commands must appear on separate lines, where each line (except the last) ends with a (backslash). The default subcommand is print. The subcommand 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 can omit it. The undo subcommand and the global subcommand itself, however, cannot appear in the command list. See also Substituting Text. Moving or Copying Text 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. Quitting an Editing Session 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 dis- card the buffer or write the buffer and then quit. Saving Text 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. Substituting Text 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. Undoing a Change Reverses the changes made in the buffer by the last buffer editing subcommand. Note that global subcommands are considered a single sub- command to an undo. You cannot undo a write or an edit subcommand. SEE ALSO
Commands: ed(1), ex(1), vi(1) edit(1)
Man Page