📄 ed.1
字号:
.\" SCCSID: @(#)ed.1 8.2 12/3/90.if t .ds ^ \^\s+4\v@.3m@^\v@-.3m@\s-4\^.if n .ds ^ ^.TH ed 1.SH Nameed, red \- text editor.SH Syntax .B ed[\fB\-\fR] [\fB\-p\fIstring\fR] [\fB\-x\fR] [\|\fIfile\fR\|].PP.B red[\fB\-\fR] [\fB\-x\fR] [\|\fIfile\fR\|].SH Description.NXR "editors" "ed".NXR "editors" "red".NXR "ed line editor".NXR "red line editor"The.PN edtext editor is the standard text editor.If you give the.I file\^argument,.PN edsimulates an.B ecommand (see below) on the named file; that is to say,the file is read into.PN ed 'sbuffer so that it can be edited.The .B \-option suppresses the printingof character counts by.IR e ,.IR r ,and.B wcommands,of diagnostics from.B eand.B qcommands,and of the.B !prompt after a\fB!\fP\fIshell\ command\^\fP.The \fB\-p\fR option allows you to specify a prompt string..NTThe .B \-xoption is available only if the Encryption layered product is installed..NEIf you supply the .B \-xoption, an.B xcommand is simulated first to handle an encrypted file.The .PN edtext editoroperates on a copy of the file it is editing; changes madeto the copy have no effect on the file until you give a.B w(write)command.The copy of the text being edited residesin a temporary file called the.IR buffer .There is onlyone buffer..PPThe.PN redtext editoris a restricted version of.PN ed .It allows editing of files only in the current directory,and prohibits executing shell commands with\fB!\fP\fIshell\ command\^\fP.Attempts to bypass these restrictions resultin an error message \fI(restricted shell)\fP..NTWhen you entertext, tab characters are expanded to every eighth column as is thedefault..NE.PPCommands to.PN edhave a simple and regular structure: zero, one, or two.I addresses\^followed by a single-charactercommand,possiblyfollowed by parameters to that command.These addresses specify one or more lines in the buffer.Every command that requires addresses has default addresses,so that the addresses can frequently be omitted..PPIn general, only one command appears on a line.Certain commands allow the input of text.This text is placed in the appropriate place in the buffer.While.PN edis accepting text, it is saidto be in.IR "input mode" .In input mode,no commands are recognized;all input is merely collected.Input mode is exited by typing a period (\^\fB.\fP\^) alone at thebeginning of a line..PPThe.PN edtext editor supports a limited form of.I "regular expression\^"notation;regular expressions are used in addresses to specifylines and in some commands(for example,.IR s )to specify portions of a line that are to be substituted.A regular expression (\s-1RE\s+1) specifiesa set of character strings.A member of this set of strings is said to be.I matched\^by the \s-1RE\s+1.The \s-1RE\s+1s allowed by.PN edare constructed as follows:.NXR "ed line editor" "constructing regular expressions".PPThe following.I one-character\^.IR \s-1RE\s+1 smatch a.I single\^character:.IP \(buAn ordinary character(\c.I not\^one of those discussed below)is aone-character \s-1RE\s+1that matches itself..IP \(buA backslash (\fB\^\e\fP) followed by any special character is aone-character \s-1RE\s+1that matches the special character itself.The special characters are:.RS.TP "\w'a.\ \ \ \ 'u"a.\&\fB.\fP,\fB\(**\fP,\fB[\fP,and\fB\^\e\fP (period, asterisk, left square bracket,and backslash, respectively), which are always special,.I except\^when they appear within square brackets (\^\fB[\|]\fP\^)..TPb.\*^ (caret or circumflex), which is special at the.I beginning\^of an.I entire\^\s-1RE\s+1(see below),or when it immediately follows the left of a pair of squarebrackets (\^\fB[\|]\fP\^) (see below)..TPc.\fB$\fP (currency symbol), which is special at the.I end\^of anentire \s-1RE\s+1(see below)..TPd.The character used to bound(that is, delimit)an entire \s-1RE\s+1, which is special for that RE (for example,see how slash (\^\fB/\fP\^) is used in the.B gcommand, below.).RE.IP \(buA period (\^\fB.\fP\^) is aone-character \s-1RE\s+1that matches any character except new-line..IP \(buA non-empty string of characters enclosed in square brackets (\^\fB[\|]\fP\^) is aone-character \s-1RE\s+1that matches.I "any one\^"character in that string.If, however, the first character of the string is a circumflex(\*^), theone-character \s-1RE\s+1matches any character.I except\^new-line and the remaining characters in the string.The \*^ has this special meaning.I only\^if itoccurs first in the string.The minus (\fB\-\fP) may be used to indicate a range of consecutiveASCII characters;for example, \fB[0\-9]\fP is equivalent to \fB[0123456789]\fP.The \fB\-\fP loses this special meaning if it occurs first (afteran initial \*^, if any)or last in the string.The right square bracket (\^\fB]\fP\^)does not terminate such a string when itis the first character within it (after an initial \*^, if any).For example,\fB[\|]a\-f]\fP matches either a right squarebracket (\^\fB]\fP\^) or one ofthe letters \fBa\fP through \fBf\fP inclusive.The four characters listed in a above stand for themselveswithin such a string of characters..PPThe following rules may be used to construct.IR \s-1RE\s+1 sfrom one-character\s-1RE\s+1s:.IP \(buA one-character \s-1RE\s+1is a\s-1RE\s+1that matches whatever theone-character \s-1RE\s+1 matches..IP \(buAone-character \s-1RE\s+1followed by an asterisk (\fB\(**\fP) is a\s-1RE\s+1that matches.I zero\^or more occurrences of theone-character \s-1RE\s+1.If there is any choice,the longest leftmost string that permits a match is chosen..IP \(buAone-character \s-1RE\s+1followed by \fB\^\e{\fP\^\fIm\fP\^\fB\e}\fP,\fB\^\e{\fP\^\fIm,\fP\^\fB\e}\fP,or\fB\^\e{\fP\^\fIm,n\fP\^\fB\e}\fP is a\s-1RE\s+1that matches a.I range\^of occurrences of theone-character \s-1RE\s+1.The values of.I m\^and.I n\^must be non-negative integers less than 256;\fB\^\e{\fP\^\fIm\fP\^\fB\e}\fPmatches.I exactly\^.I m\^occurrences;\fB\^\e{\fP\^\fIm,\fP\^\fB\e}\fPmatches.I "at least\^".I m\^occurrences;\fB\^\e{\fP\^\fIm,n\fP\^\fB\e}\fPmatches.I "any number\^"of occurrences.I between\^.I m\^and.I n\^inclusive.Whenever a choice exists,the\s-1RE\s+1matches as many occurrences as possible..IP \(buThe concatenation of\s-1RE\s+1sis a\s-1RE\s+1that matches the concatenation of the strings matched by each component of the\s-1RE\s+1..IP \(buA\s-1RE\s+1enclosed between the character sequences\fB\^\e(\fP and \fB\^\e)\fPis a\s-1RE\s+1that matches whatever the unadorned\s-1RE\s+1matches..IP \(buThe expression \fB\^\e\fP\fIn\fP\^ matches the same string of charactersas wasmatched by an expression enclosed between \fB\^\e(\fP and \fB\^\e)\fP.I earlier\^in the same \s-1RE\s+1.Here.I n\^is a digit;the sub-expression specified is that beginning with the.IR n \-thoccurrence of \fB\^\e(\fP counting from the left.For example, the expression \*^\fB\e(.\(**\e)\e1$\fP matches a lineconsisting of two repeated appearances of the same string..PPFinally, an.I entire\^.I \s-1RE\s+1\^may be constrained to match only an initial segment or final segmentof a line (or both):.IP \(buA circumflex (\*^) at the beginning of anentire \s-1RE\s+1constrains that \s-1RE\s+1 to match an.I initial\^segment of a line..IP \(buA currency symbol (\^\fB$\fP\^)at the end of anentire \s-1RE\s+1constrains that\s-1RE\s+1to match a.I final\^segment of a line..PPThe construction\%\*^\fIentire \s-1RE\s+1\fP\|\fB$\fPconstrains theentire \s-1RE\s+1to match the entire line..PPThe null \s-1RE\s+1 (for example, \fB//\fP)is equivalent to the last \s-1RE\s+1 encountered.See also the last paragraph beforeFILESbelow..PPTo understand addressing in.PN edit is necessary to know that at any time there is a.IR "current line" .Generally speaking, the current line isthe last line affected by a command;the exact effect on the current lineis discussed under the description ofeach command..I Addresses\^are constructed as follows:.NXR "ed line editor" "constructing addresses".TP "\w'1.1\ \ \ \ 'u"\01.The character \fB.\fP addresses the current line..TP\02.The character \fB$\fP addresses the last line of the buffer..TP\03.A decimal number.I n\^addresses the.IR n \-thline of the buffer..TP\04.\fI\(fmx\fP\^ addresses the line marked with themark name character.IR x ,which must be a lower-case letter.Lines are marked with the.B kcommand described below..TP\05.A \s-1RE\s+1 enclosed by slashes (\^\fB/\fP\^) addressesthe first line found by searching.I forward\^from the line.I following\^the current linetoward the end of thebuffer and stopping at the first line containing astring matching the \s-1RE\s+1.If necessary, the search wraps around to the beginning of thebufferand continues up to and including the current line, so that the entirebuffer is searched.See also the last paragraph beforeFILESbelow..TP\06.A \s-1RE\s+1 enclosed in question marks (\^\fB?\fP\^) addressesthe first line found by searching.I backward\^from the line.I preceding\^the current linetoward the beginning ofthe buffer and stopping at the first line containinga string matching the \s-1RE\s+1.If necessary,the search wraps around to the end of the bufferand continues up to and including the current line.See also the last paragraph beforeFILESbelow..TP\07.An address followed by a plus sign (\^\fB+\fP\^)or a minus sign (\fB\-\fP) followed by a decimal number specifies that address plus(respectively minus) the indicated number of lines.The plus sign may be omitted..TP\08.If an address begins with \fB+\fP or \fB\-\fP,the addition or subtraction is taken with respect to the current line.For example, \fB\-5\fP is understood to mean \fB.\-5\fP..TP\09.If an address ends with \fB+\fP or \fB\-\fP,then 1 is added to or subtracted from the address, respectively.As a consequence of this rule and of rule 8 immediately above,the address \fB\-\fP refers to the line preceding the current line.(To maintain compatibility with earlier versions of the editor,the character \*^ in addresses is entirelyequivalent to \fB\-\fP.)Moreover,trailing\fB+\fP and \fB\-\fP charactershave a cumulative effect, so \fB\-\-\fP refers to the currentline less 2..TP10.For convenience, a comma (\^\fB,\fP\^) stands for theaddress pair \fB1,\^$\fP,while a semicolon (\^\fB;\fP\^) stands for thepair \fB.\^,\^$\fP..br.if \n()s .bp.PPCommands may require zero, one, or two addresses.Commands that require no addresses regard the presenceof an address as an error.Commands that accept one or two addressesassume default addresses when an insufficient number of addresses is given;if more addresses are given than such a command requires,the last one(s) are used..PPTypically, addresses are separated from each other by a comma(\^\fB,\fP\^).They may also be separated by a semicolon(\^\fB;\fP\^).In the latter case, the current line (\^\fB.\fP\^) is set tothe first address,and only then is the second address calculated.This feature can be used to determine the startingline for forward and backward searches (see rules 5. and 6. above).The second address of any two-address sequencemust correspond to a line that follows, in the buffer, the line corresponding to the first address..PPIn the following list of.PN edcommands, the default addressesare shown in parentheses..NXR "ed line editor" "command list"The parentheses are.I not\^part ofthe address; they show that the given addresses arethe default..PPIt is generally illegal for more than onecommand to appear on a line.However, any command(except.B e,.B f,.B r,or.B w)may be suffixed by \fBl\fP, \fBn\fPor \fBp\fP, in which casethe current line is eitherlisted, numbered or printed, respectively,as discussed below under the.B l,.B nand.B pcommands..TP 20.B (\|.\|)a.ns.TP<text>.ns.TP\&\fB.\fPThe appendcommand reads the given textand appends it after the addressed line;\&\fB.\fP is leftat the last inserted line, or, if therewere none, at the addressed line.Address 0 is legal for this command: it causes the ``appended'' text to be placedat the beginning of the buffer.The maximum number of characters that may be entered from aterminal is 256 per line (including the new line character)..HP.B (\|.\|)c.br.ns.HP<text>.br.ns.HP.if t .rs.if t .sp -.5v\&\fB.\fP.brThe changecommand deletes the addressed lines, then accepts inputtext that replaces these lines;\&\fB.\fP is left at the last line input, or, if there were none,at the first line that was not deleted..HP.B (\|.\|,\|.\|)d.brThe deletecommand deletes the addressed lines from the buffer.The line after the last line deleted becomes the current line;if the lines deleted were originally at the end of the buffer,the new last line becomes the current line..HP.BI e " file\^".brThe editcommand causes the entire contents of the buffer to be deleted,and then the named file to be read in;\&\fB.\fP is set to the last line of the buffer.If no file name is given, the currently-remembered file name, if any, is used(see the.B fcommand).The number of characters read is typed;.I file\^is remembered for possible use as a default file namein subsequent.B e,.B r,and.B w "commands."If.I file\^is replaced by \fB!\fP, the rest of the lineis taken to be ashell, sh(1),command whose output is to be read.Such ashellcommand is.B notremembered as the current file name.See alsoDIAGNOSTICSbelow..HP.BI E " file\^".brThe .PN editcommand is like.B e,except that the editor does not check to seeif any changes have been made to the buffer sincethe last.B wcommand..HP.BI f " file\^".brIf.I file\^is given,the file-namecommand changesthe currently-remembered file name to.IR file ;otherwise, it prints the currently-remembered file name..HP.BI (\|1\|,\|$\|)g/ \s-1RE\s+1 / "command list\^".brIn the globalcommand, the first step is to mark every line that matchesthe given\s-1RE\s+1.Then, for every such line, the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -