📄 ed.1
字号:
.th ED I 1/15/73.if t .ds q \(aa.if n .ds q '.sh NAMEed \*- text editor.sh SYNOPSIS.bd ed[.bd \*-] [ name ].sh DESCRIPTION.it Edis the standard text editor..s3If a.it nameargument is given,.it edsimulates an.it ecommand (see below)\| on the named file; that is to say,the file is read into.it ed'sbuffer so that it can be edited.The optional.bd \*-suppresses the printingof character counts by.it e,.it r,and.it wcommands..s3.it Edoperates on a copy of any file it is editing; changes madein the copy have no effect on the file until a \fIw\fR (write)\|command is given.The copy of the text being edited residesin a temporary file called the .it buffer.There is onlyone buffer..s3Commands to.it edhave a simple and regular structure: zero ormore.it addressesfollowed by a single character.it command,possiblyfollowed by parameters to the command.These addresses specify one or more lines in the buffer.Every command which requires addresses has default addresses,so that the addresses can often be omitted..s3In general, only one command may appear on a line.Certain commands allow the input of text.This text is placed in the appropriate place in the buffer.While.it edis accepting text, it is saidto be in\fIinput mode.\fRIn this mode, no commands are recognized;all input is merely collected.Input mode is left by typing a period `\fB.\fR' alone at thebeginning of a line..s3.it Edsupports a limited form of.it "regular expression"notation.A regular expression specifiesa set of strings of characters.A member of this set of strings is said to be.it matchedby the regular expression.The regular expressions allowed by.it edare constructed as follows:.s3.lp +3 31. An ordinary character (not one of those discussed below)\|is a regular expression and matches that character..s3.lp +3 32. A circumflex `^' at the beginning of a regular expressionmatches the empty string at the beginning of a line..s3.lp +3 33. A currency symbol `$' at the end of a regular expressionmatches the null character at the end of a line..s3.lp +3 34. A period `\fB.\fR' matches any character except a new-line character..s3.lp +3 35. A regular expression followed by an asterisk `*'matches any number of adjacent occurrences (including zero)\|of the regular expression it follows..s3.lp +3 36. A string of characters enclosed in square brackets`[ ]' matches any character in the string but no others.If, however, the first character of the string is a circumflex`^' the regular expression matches any character except new-lineand the characters in the string..s3.lp +3 37. The concatenation of regular expressions is a regularexpression which matches the concatenation of the stringsmatched by the components of the regular expression..s3.lp +3 38. A regular expression enclosed betweenthe sequences`\\(' and `\\)'is identical to theunadorned expression; the construction has side effects discussedunder the.it scommand..s3.lp +3 39. The null regular expression standing aloneis equivalent to the last regular expression encountered..s3.i0Regular expressions are used in addresses to specifylines and in one command(see.it sbelow)\|to specify a portion of a line which is to be replaced.If it is desired to use one ofthe regular expression metacharacters as an ordinarycharacter, that character may be preceded by `\\'.This also applies to the character bounding the regularexpression (often `/')\| and to `\\' itself..s3To understand addressing in.it edit is necessary to know that at any time there is a\fIcurrent line.\fRGenerally speaking, the current line isthe last line affected by a command; however,the exact effect on the current lineis discussed under the description ofthe command.Addresses are constructed as follows..s3.lp +6 31. The character `\fB.\fR' addresses the current line..s3.lp +6 32. The character `$' addresses the last line of the buffer..s3.lp +6 33. A decimal number.it naddresses the\fIn\fR-thline of the buffer..s3.lp +6 34. `\*q\fIx\fR' addresses the line marked with themark name character \fIx\fR,which must be a lower-case letter.Lines are marked with the.it kcommand described below..s3.lp +6 35. A regular expression enclosed in slashes `/' addressesthe first line found by searching toward the end of thebuffer and stopping at the first line containing astring matching the regular expression.If necessary the search wraps around to the beginning of thebuffer..s3.lp +6 36. A regular expression enclosed in queries `?' addressesthe first line found by searching toward the beginning ofthe buffer and stopping at the first line containinga string matching the regular expression.If necessarythe search wraps around to the end of the buffer..s3.lp +6 37. An address followed by a plus sign `+'or a minus sign `\*-' followed by a decimal number specifies that address plus(resp. minus)\| the indicated number of lines.The plus sign may be omitted..s3.lp +6 38. If an address begins with `+' or `\-'the addition or subtraction is taken with respect to the current line;e.g. `\-5' is understood to mean `\fB.\fR\-5'..s3.lp +6 39. If an address ends with `+' or `\-',then 1 is added (resp. subtracted).As a consequence of this rule and rule 8,the address `\-' refers to the line before the current line.Moreover,trailing`+' and `\-' charactershave cumulative effect, so `\-\-' refers to the currentline less 2..s3.lp +6 310. To maintain compatibility with earlier version of the editor,the character `^' in addresses is entirelyequivalent to `\-'..s3.i0Commands may require zero, one, or two addresses.Commands which require no addresses regard the presenceof an address as an error.Commands which accept one or two addressesassume default addresses when insufficient are given.If more addresses are given than such a command requires,the last one or two (depending on what is accepted)\| are used..s3Addresses are separated from each other typically by a comma`\fB,\fR'.They may also be separated by a semicolon`\fB;\fR'.In this case the current line `\fB.\fR' is set tothe previous address before the next address is interpreted.This feature can be used to determine the startingline for forward and backward searches (`/', `?')\|.The second address of any two-address sequencemust correspond to a line following the line corresponding to the first address..s3In the following list of.it edcommands, the default addressesare shown in parentheses.The parentheses are not part ofthe address, but are used to show that the given addresses arethe default..s3As mentioned, it is generally illegal for more than onecommand to appear on a line.However, any command may be suffixed by `p'or by `l', in which casethe current line is eitherprinted or listed respectivelyin the way discussed below..s3.lp +5 5( \fB. \fR)\|a.lp +5 5<text>.lp +5 5.li\fB.\fR.lp +5 5 The append command reads the given textand appends it after the addressed line.`\fB.\fR' is lefton the last line input, if therewere any, otherwise at the addressed line.Address `0' is legal for this command; text is placedat the beginning of the buffer..s3.lp +5 5( \fB. \fR, \fB. \fR)\|c.lp +5 5<text>.lp +5 5.li\fB.\fR.lp +5 5 The changecommand deletes the addressed lines, then accepts inputtext which replaces these lines.`\fB.\fR' is left at the last line input; if there were none,it is left at the first line not deleted..s3.lp +5 5( \fB. \fR, \fB. \fR)\| d.brThe delete command deletes the addressed lines from the buffer.The line originally after the last line deleted becomes the current line;if the lines deleted were originally at the end,the new last line becomes the current line..s3.lp +5 5e filename.brThe editcommand causes the entire contents of the buffer to be deleted,and then the named file to be read in.`\fB.\fR' is set to the last line of the buffer.The number of characters read is typed.`filename' is remembered for possible use as a default file namein a subsequent.it ror.it wcommand..s3.lp +5 5f filename.brThe filename command prints the currently remembered file name.If `filename' is given,the currently remembered file name is changed to `filename'..s3.lp +5 5(1,$)\|g/regular expression/command list.brIn the globalcommand, the first step is to mark every line which matchesthe given regular expression.Then for every such line, thegiven command list is executed with `\fB.\fR' initially set to that line.A single command or the first of multiple commandsappears on the same line with the global command.All lines of a multi-line list except the last line must be ended with `\\'..it A,.it i,and.it ccommands and associated input are permitted;the `\fB.\fR' terminating input mode may be omitted if it would be on thelast line of the command list.The (global)\| commands,.it g,and.it v,are not permitted in the command list..s3.lp +5 5( \fB. \fR)\|i.lp +5 5<text>.lp +5 5.li\fB.\fR.brThis command inserts the given text before the addressed line.`\fB.\fR' is left at the last line input; if there were none,at the addressed line.This command differs from the.it acommand only in the placement of thetext..s3.lp +5 5( \fB. \fR)\|k\fIx\fR.brThe mark command marks the addressed line withname.it x,which must be a lower-case letter.The address form `\*q\fIx\fR' then addresses this line..s3.lp +5 5( \fB. \fR, \fB. \fR)\|l.brThe list commandprints the addressed lines in an unambiguous way:non-graphic characters areprinted in octal,and long lines are folded.An.it lcommand may follow any other on the same line..s3.lp +5 5( \fB. \fR, \fB. \fR)\|m\fIa\fR.brThe move command repositions the addressed lines after the lineaddressed by.it a.The last of the moved lines becomes the current line..s3.lp +5 5( \fB. \fR, \fB. \fR)\|p.brThe print command prints the addressed lines.`\fB.\fR'is left at the last line printed.The.it pcommandmaybe placed on the same line after any command..s3.lp +5 5q.brThe quit command causes.it edto exit.No automatic writeof a file is done..s3.lp +5 5($)\|r filename.brThe read commandreads in the given file after the addressed line.If no file name is given,the remembered file name, if any, is used(see.it eand.it fcommands)\|.The remembered file name is not changed unless`filename' is the very first file namementioned.Address `0' is legal for.it rand causes thefile to be read at the beginning of the buffer.If the read is successful, the number of charactersread is typed.`\fB.\fR' is left at the last line read in from the file..s3.lp +5 5( \fB. \fR, \fB. \fR)\|s/regular expression/replacement/ or,.lp +5 5( \fB. \fR, \fB. \fR)\|s/regular expression/replacement/g.brThe substitute command searches each addressedline for an occurrence of the specified regular expression.On each line in which a match is found,all matched strings are replaced by the replacement specified,if the global replacement indicator `g' appears after the command.If the global indicator does not appear, only the first occurrenceof the matched string is replaced.It is an error for the substitution to fail on all addressed lines.Any character other than space or new-linemay be used instead of `/' to delimit the regular expressionand the replacement.`\fB.\fR' is left at the last line substituted..s2An ampersand `&' appearing in the replacementis replaced by the string matching the regular expression.The special meaning of `&' in this context may besuppressed by preceding it by `\\'.As a more general feature,the characters`\\\fIn\fR',where.it nis a digit,are replaced by the text matched by the\fIn\fR-thregular subexpressionenclosed between `\\(' and `\\)'.Whennested, parenthesized subexpressionsare present,.it nis determined by counting occurrences of `\\(' starting from the left..s2Lines may be split by substituting new-line characters into them.The new-line in thereplacement stringmust be escaped by preceding it by `\\'..s3.lp +5 5( \fB.\fR , \fB.\fR ) t \fIa\fR.brThis command acts just like the.it mcommand, except that a copy of the addressed lines is placedafter address.it a(which may be 0).`\fB.\fR' is left on the last line of the copy..s3.lp +5 5(1,$)\|v/regular expression/command list.brThis command is the same as the global commandexcept that the command list is executedwith `\fB.\fR' initially set to every line.it exceptthosematching the regular expression..s3.lp +5 5(1,$)\|w filename.brThe write command writes the addressed lines ontothe given file.If the file does not exist,it is created mode 666 (readable and writeable by everyone)\|.The remembered file name is.it notchanged unless`filename' is the very first file name mentioned.If no file name is given,the remembered file name, if any, is used(see.it eand.it fcommands)\|.`\fB.\fR' is unchanged.If the command is successful, the number of characters written istyped..s3.lp +5 5($)\|=.brThe line number of the addressed line is typed.`\fB.\fR' is unchanged by this command..s3.lp +5 5!UNIX command.brThe remainder of the line after the `!' is sentto UNIX to be interpreted as a command.`\fB.\fR' is unchanged..s3.lp +5 5( \fB.\fR+1 )\|<newline>.brAn address alone on a line causes the addressed line to be printed.A blank line alone is equivalent to `.+1p'; it is usefulfor stepping through text..s3.i0If an interrupt signal (ASCII DEL)\| is sent,.it edprints a `?' and returns to its command level..s3Some size limitations:512 characters per line,256 characters per global command list,64 characters per file name,and 128K characters in the temporary file.The limit on the number of lines depends on the amount of core:each line takes 1 word..sh FILES/tmp/#, temporary;`#' is the process number (in octal)..sh DIAGNOSTICS`?' forerrors in commands;`TMP' for temporary file overflow..sh "SEE ALSO"A Tutorial Introduction to the ED Text Editor(B. W. Kernighan).sh BUGSThe.it scommand causes all marksto be lost on lines changed.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -