EDIT(1,C) AIX Commands Reference EDIT(1,C) ------------------------------------------------------------------------------- edit PURPOSE Starts a line editor that is designed for the new user. SYNTAX +------+ edit ---| |-- file --| +- -r -+ ^ | +------+ DESCRIPTION The edit command starts a line editor that is designed for beginning users. It is a simplified version of the ex command (see "ex"). To edit the contents of a file, enter: "edit" file If file is the name of an existing file, the edit command copies the file to a buffer and displays the number of lines and characters in it. (Both the file and the file name can contain Japanese characters.) Then it displays a colon prompt (":") to show that it is ready to read subcommands from standard input. If file does not already exist, the edit command tells you this, but still stores the name as the current file name. You can give more than one file name, 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 command operates in one of two modes: command mode and text entry mode. In command mode, the edit command displays the colon prompt to show you that it is ready to accept edit subcommands. In text entry mode, edit places all input into its editing buffer. The general format of an edit subcommand is as follows: [addr]subcommand [parameters] [count] The addr 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. If you do not specify addr, the edit command works on the current line. If you add a numeric count to most subcommands, edit works on the specified number of lines. Processed November 8, 1990 EDIT(1,C) 1 EDIT(1,C) AIX Commands Reference EDIT(1,C) For most subcommands, the last line affected becomes the new current line. That means, for example, that after the edit command reads a file into its buffer, the last line in the file becomes the current line. 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 address /pattern/ the edit command searches forward for pattern, while given ?pattern? it searches backwards for pattern. (The pattern can contain Japanese characters.) If a forward search reaches the end of the buffer without finding pattern, the search continues from the beginning of the file until it reaches the current line. A backwards search does just the reverse. The following characters have special meanings in forward and backward searches: ^ 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. The current line has a symbolic name, dot ("."), and the last line in the buffer has a symbolic name, dollar sign ("$"), that you can use in addresses. These symbolic names are useful when working with a range of lines. For example, .,$print displays all lines from the current line to the last line in the buffer. You can combine these symbols with numbers to reference lines, so that "$-5" refers to the fifth line from the last and ".+20" refers to the line 20 lines beyond the current line. You can also use these symbols with the = (equal) 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 the Enter key. To display the next half-screen of lines, press Ctrl-D. Processed November 8, 1990 EDIT(1,C) 2 EDIT(1,C) AIX Commands Reference EDIT(1,C) Note: Do not confuse the meaning of "$" in text patterns (end of line) with its meaning in addresses (last line). THE FAMILY OF EDITORS The edit command is part of a family of editors that includes edit, ex, and vi. The edit command starts a simple line editor that is designed for beginning users. It is a simplified version of the ex editor. After you become more experienced with the edit editor, you may want to try the advanced features of one of the other editors in the family. Because the edit editor is part of a family of editors, you can apply your knowledge of this editor 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 ^, "$", and \ have special meanings as pattern-matching characters; however, several additional characters also have special meanings in ex. For more information on the ex editor, see "ex." The vi editor is a display-based editor designed for experienced users who do a lot of editing at their display. It contains many of the advanced features of the ex editor, but focuses on the display editing portion of ex. The edit editor prevents you from accidentally entering vi's two alternative modes of editing, the open mode and the visual mode. For more information on the vi editor, see "vi, vedit, view." FLAG -r Recovers file after an editor or system crash. PARAMETERS You can enter most edit subcommands as either a complete word or an abbreviation. In the following list, a subcommand abbreviation appears in parentheses. Unless noted otherwise, all subcommands work by default on the current line. When the edit command displays the colon (:) prompt, you can enter these subcommands: [addr]append (a) text . Reads the input text into the file being edited, placing text after the line at the address specified by addr. If you specify address 0, edit places the text at the beginning of the buffer. To return to command mode, enter a line with only a . (period) in the first position. [addr1[,addr2]]change (c) Processed November 8, 1990 EDIT(1,C) 3 EDIT(1,C) AIX Commands Reference EDIT(1,C) text . Replaces the specified line or lines with the input text. If any lines are input, the last input line becomes the new current line. [addr1[,addr2]]delete [buffer] (d) 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", the specified lines are saved in that buffer or, if the letter is uppercase, appends the lines to that buffer. edit file (e) Begins an editing session on a new file. The editor first checks to see if the buffer has been modified (edited) since the last write subcommand was entered. 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 file name. After ensuring that this file can be edited, it reads the file into its buffer. If the edit command 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. file (f) Displays the current file name along with the following information about it: o Whether it has been modified since the last write subcommand was entered. o What the current line is. o How many lines are in the buffer. o What percentage of the way through the buffer the current line is. file file Changes the name of the current file to file. The edit command considers this file not edited. [addr1[,addr2]]global/pattern/cmds (g) Marks each of the specified lines that matches pattern. Then the edit command carries out the specified subcommands (cmds) on each marked line. A single cmd or the first cmd in a subcommand list appears on same line as global. The remaining cmds must appear on separate lines, where each line (except the last) ends with a \ (backslash). The default subcommand is print. Processed November 8, 1990 EDIT(1,C) 4 EDIT(1,C) AIX Commands Reference EDIT(1,C) The 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 may omit it. The undo subcommand and the global subcommand itself, however, may not appear in the command list. [addr]insert (i) text . Places the given text before the specified line. The last line input becomes the current line. Otherwise, the current line does not change. [addr1[,addr2]]move addr3 (m) Repositions the specified line or lines to follow addr3. The first line moved becomes the current line. next (n) Copies the next file in the command-line argument list to the buffer for editing. [addr1[,addr2]]number (nu) Displays each specified line or lines preceded by its buffer line number. The last line displayed becomes the current line. preserve 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. [addr1[,addr2]]print (p) Displays the specified line or lines. The last line displayed becomes the current line. [addr]put buffer (pu) Retrieves the contents of the specified buffer and places it after addr. If you do not specify a buffer, the edit command restores the last deleted or yanked text. Thus you can use this subcommand together with the delete command to move lines or with the yank command to duplicate lines between files. Processed November 8, 1990 EDIT(1,C) 5 EDIT(1,C) AIX Commands Reference EDIT(1,C) quit (q) quit! (q!) Ends the editing session. Note: The quit command does not write the editor buffer to a file. However, if you have modified the contents of the buffer since entering the last write command, edit displays a warning message and does not end the session. In this case, either use the quit! subcommand to discard the buffer or the write command to the buffer and then use the quit command. recover file Recovers file from the system save area. Use this command after a system crash or after using a preserve subcommand. [addr1[,addr2]]substitute/pattern/repl/ (s) [addr1[,addr2]]substitute/pattern/repl/g Replaces on each specified line the first instance of pattern with the replacement pattern repl. If you add the g flag, it replaces all instances of pattern on each specified line. undo (u) 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 command. You cannot undo a write or an edit command. [addr1,[addr2]]write file (w) Writes the contents of the specified line or lines to file. The default range is all lines in the buffer. The edit command displays the number of lines and characters that it writes. If you do not specify a file, the edit command uses the current file name. If file does not exist, the edit command creates it. [addr1,[addr2]]yank [buffer] (ya) Places the specified line or lines in buffer, which is a single alpha character a through z. [addr]z Displays a screen of text, beginning with the specified line. [addr]z- Displays a screen of text, with the specified line at the bottom of the screen. Processed November 8, 1990 EDIT(1,C) 6 EDIT(1,C) AIX Commands Reference EDIT(1,C) [addr]z. Displays a screen of text, with the specified line in the middle of the screen. RELATED INFORMATION See the following commands: "ed, red," "ex," and "vi, vedit, view." Processed November 8, 1990 EDIT(1,C) 7