Annotation of 43BSDReno/share/doc/usd/12.edtut/e3, revision 1.1

1.1     ! root        1: .\"    @(#)e3  6.1 (Berkeley) 5/22/86
        !             2: .\"
        !             3: .SH
        !             4: The current line \- ``Dot'' or ``.''
        !             5: .PP
        !             6: Suppose your buffer still contains the six lines as above,
        !             7: that you have just typed
        !             8: .P1
        !             9: 1,3p
        !            10: .P2
        !            11: and
        !            12: .ul
        !            13: ed
        !            14: has printed the three lines for you.
        !            15: Try typing just
        !            16: .P1
        !            17: p      (no line numbers)
        !            18: .P2
        !            19: This will print
        !            20: .P1
        !            21: to come to the aid of their party.
        !            22: .P2
        !            23: which is the third line of the buffer.
        !            24: In fact it is the last
        !            25: (most recent) line that you have done anything with.
        !            26: (You just printed it!)
        !            27: You can
        !            28: repeat this
        !            29: .UL p
        !            30: command without line numbers, and
        !            31: it will continue to print line 3.
        !            32: .PP
        !            33: The reason is that
        !            34: .ul
        !            35: ed
        !            36: maintains a record of the last line
        !            37: that you did anything to (in this case, line 3, which you
        !            38: just printed) so that it can be used instead of an explicit
        !            39: line number.
        !            40: This most recent line is referred to by the
        !            41: shorthand symbol
        !            42: .P1
        !            43: \&\*.  (pronounced ``dot'').
        !            44: .P2
        !            45: Dot is a line number in the same way that
        !            46: .UL $
        !            47: is; it means
        !            48: exactly ``the current line'', or loosely,
        !            49: ``the line you most recently did something to.''
        !            50: You
        !            51: can use it in several ways \- one possibility
        !            52: is to say
        !            53: .P1
        !            54: \&\*.,$p
        !            55: .P2
        !            56: This will print all the lines from (including) the current
        !            57: line to the
        !            58: end of the buffer.
        !            59: In our example these are lines 3 through 6.
        !            60: .PP
        !            61: Some commands change the value of dot, while others do not.
        !            62: The
        !            63: .UL p
        !            64: command sets dot to the number of the last line printed;
        !            65: the last command will
        !            66: set both
        !            67: \*.
        !            68: and
        !            69: .UL $
        !            70: to 6.
        !            71: .PP
        !            72: Dot is most useful when used in combinations like this one:
        !            73: .P1
        !            74: \&\*.+1        (or equivalently, \*.+1p)
        !            75: .P2
        !            76: This means ``print the next line'' and is a handy way to step
        !            77: slowly through a buffer.
        !            78: You can also say
        !            79: .P1
        !            80: \&\*.\-1       (or \*.\-1p )
        !            81: .P2
        !            82: which means ``print the line
        !            83: .ul
        !            84: before
        !            85: the current line.''
        !            86: This enables you to go backwards if you wish.
        !            87: Another useful one is something like
        !            88: .P1
        !            89: \&\*.\-3,\*.\-1p
        !            90: .P2
        !            91: which prints the previous three lines.
        !            92: .PP
        !            93: Don't forget that all of these change the value of dot.
        !            94: You can find out what dot is at any time by typing
        !            95: .P1
        !            96: \&\*.=
        !            97: .P2
        !            98: .ul
        !            99: Ed
        !           100: will respond by printing the value of dot.
        !           101: .PP
        !           102: Let's summarize some things about the
        !           103: .UL p
        !           104: command
        !           105: and dot.
        !           106: Essentially
        !           107: .UL p
        !           108: can be preceded by 0, 1, or 2 line numbers.
        !           109: If there is no line number given, it prints the ``current line'',
        !           110: the line that dot refers to.
        !           111: If there is one line number given
        !           112: (with or without the letter
        !           113: .UL p ),
        !           114: it prints that line (and dot is set there); and if there
        !           115: are two line numbers, it prints all the lines in that range
        !           116: (and sets dot to the last line printed.)
        !           117: If two line numbers are specified
        !           118: the first can't be bigger than the second (see Exercise 2.)
        !           119: .PP
        !           120: Typing a single return will cause printing of the next line \-
        !           121: it's
        !           122: equivalent to
        !           123: .UL .+1p .
        !           124: Try it.
        !           125: Try typing
        !           126: a
        !           127: .UL \- ;
        !           128: you will find that
        !           129: it's equivalent to
        !           130: .UL .\-1p .
        !           131: .SH
        !           132: Deleting lines: the ``d'' command
        !           133: .PP
        !           134: Suppose you want to get rid of the three extra lines in the buffer.
        !           135: This is done by the
        !           136: .ul
        !           137: delete
        !           138: command
        !           139: .P1
        !           140: d
        !           141: .P2
        !           142: Except that
        !           143: .UL d
        !           144: deletes lines instead of printing them,
        !           145: its action is similar to that of
        !           146: .UL p .
        !           147: The lines to be deleted are specified for
        !           148: .UL d
        !           149: exactly as they are for
        !           150: .UL p :
        !           151: .P1
        !           152: \fIstarting line, ending line\fP d
        !           153: .P2
        !           154: Thus the command
        !           155: .P1
        !           156: 4,$d
        !           157: .P2
        !           158: deletes lines 4 through the end.
        !           159: There are now three lines left, as you can check by using
        !           160: .P1
        !           161: 1,$p
        !           162: .P2
        !           163: And notice that
        !           164: .UL $
        !           165: now is line 3!
        !           166: Dot
        !           167: is set to the next line after the last line deleted,
        !           168: unless the last line deleted is the last line in the buffer.
        !           169: In that case, dot is set to
        !           170: .UL $ .
        !           171: .SH
        !           172: Exercise 4:
        !           173: .PP
        !           174: Experiment with
        !           175: .UL a ,
        !           176: .UL e ,
        !           177: .UL r ,
        !           178: .UL w ,
        !           179: .UL p
        !           180: and
        !           181: .UL d
        !           182: until you are sure that you
        !           183: know what they do, and until you understand how dot,
        !           184: .UL $ ,
        !           185: and
        !           186: line numbers are used.
        !           187: .PP
        !           188: If you are adventurous, try using line numbers with
        !           189: .UL a ,
        !           190: .UL r
        !           191: and
        !           192: .UL w
        !           193: as well.
        !           194: You will find that
        !           195: .UL a
        !           196: will append lines
        !           197: .ul
        !           198: after
        !           199: the line number that you specify (rather than after dot); that
        !           200: .UL r
        !           201: reads
        !           202: a file in
        !           203: .ul
        !           204: after
        !           205: the line number you specify (not necessarily
        !           206: at the end of the buffer); and that
        !           207: .UL w
        !           208: will write out exactly the lines
        !           209: you specify, not necessarily the whole buffer.
        !           210: These variations are sometimes handy.
        !           211: For instance you can insert a file at the beginning of a buffer
        !           212: by saying
        !           213: .P1
        !           214: 0r filename
        !           215: .P2
        !           216: and you can enter lines at the beginning of the buffer
        !           217: by saying
        !           218: .P1
        !           219: 0a
        !           220: \&. . . \fItext\fP . . .
        !           221: \*.
        !           222: .P2
        !           223: Notice that
        !           224: .UL .w
        !           225: is
        !           226: .ul
        !           227: very
        !           228: different from
        !           229: .P1
        !           230: \*.
        !           231: w
        !           232: .P2
        !           233: .SH
        !           234: Modifying text: the Substitute command ``s''
        !           235: .PP
        !           236: We are now ready to try one of the most important
        !           237: of all commands \- the substitute command
        !           238: .P1
        !           239: s
        !           240: .P2
        !           241: This is the command
        !           242: that is used to change individual
        !           243: words or letters within a line or group of lines.
        !           244: It is what you use, for example, for correcting spelling
        !           245: mistakes and typing errors.
        !           246: .PP
        !           247: Suppose that by a typing error, line 1 says
        !           248: .P1
        !           249: Now is th time
        !           250: .P2
        !           251: \- the
        !           252: .IT e
        !           253: has been left off
        !           254: .IT the .
        !           255: You can use
        !           256: .UL s
        !           257: to fix this up as follows:
        !           258: .P1
        !           259: 1s/th/the/
        !           260: .P2
        !           261: This says: ``in line 1, substitute for the characters
        !           262: .IT th
        !           263: the characters
        !           264: .IT the .''
        !           265: To verify
        !           266: that it works
        !           267: .IT ed "" (
        !           268: will not print
        !           269: the result automatically) say
        !           270: .P1
        !           271: p
        !           272: .P2
        !           273: and get
        !           274: .P1
        !           275: Now is the time
        !           276: .P2
        !           277: which is what you wanted.
        !           278: Notice that dot must have been set to the line
        !           279: where the substitution took place, since the
        !           280: .UL p
        !           281: command
        !           282: printed that line.
        !           283: Dot is always set this way with the
        !           284: .UL s
        !           285: command.
        !           286: .PP
        !           287: The general way to use the substitute command is
        !           288: .P1
        !           289: \fIstarting\(hyline, ending\(hyline\fP s/\fIchange this\fP/\fIto this\fP/
        !           290: .P2
        !           291: Whatever string of characters is between the first pair of
        !           292: slashes is replaced by whatever is between the second pair,
        !           293: in
        !           294: .ul
        !           295: all
        !           296: the lines between
        !           297: .ul
        !           298: starting-line
        !           299: and
        !           300: .ul
        !           301: ending-line.
        !           302: Only the first occurrence on each line is changed, however.
        !           303: If you want to change
        !           304: .ul
        !           305: every
        !           306: occurrence, see Exercise 5.
        !           307: The rules for line numbers are the same as those for
        !           308: .UL p ,
        !           309: except that dot is set to the last line changed.
        !           310: (But there is a trap for the unwary: if no substitution
        !           311: took place, dot is
        !           312: .ul
        !           313: not
        !           314: changed.
        !           315: This causes an error
        !           316: .UL ?
        !           317: as a warning.)
        !           318: .PP
        !           319: Thus you can say
        !           320: .P1
        !           321: 1,$s/speling/spelling/
        !           322: .P2
        !           323: and correct the first spelling mistake
        !           324: on each line
        !           325: in the text.
        !           326: (This is useful for people who are consistent
        !           327: misspellers!)
        !           328: .PP
        !           329: If no line numbers are given, the
        !           330: .UL s
        !           331: command assumes we mean
        !           332: ``make the substitution on line dot'', so it changes things only
        !           333: on the current line.
        !           334: This leads to the very common sequence
        !           335: .P1
        !           336: s/something/something else/p
        !           337: .P2
        !           338: which makes some correction on the
        !           339: current line, and then prints it, to make sure it
        !           340: worked out right.
        !           341: If it didn't,
        !           342: you can try again.
        !           343: (Notice that there is
        !           344: a
        !           345: .UL p
        !           346: on the same line as the
        !           347: .UL s
        !           348: command.
        !           349: With few exceptions,
        !           350: .UL p
        !           351: can follow any command;
        !           352: no other multi-command lines are legal.)
        !           353: .PP
        !           354: It's also legal to say
        !           355: .P1
        !           356: s/ . . . //
        !           357: .P2
        !           358: which means ``change the first
        !           359: string of characters to
        !           360: .IT nothing '', ``
        !           361: i.e.,
        !           362: remove them.
        !           363: This is useful for deleting extra words in a line or removing extra
        !           364: letters from words.
        !           365: For instance, if you had
        !           366: .P1
        !           367: Nowxx is the time
        !           368: .P2
        !           369: you can say
        !           370: .P1
        !           371: s/xx//p
        !           372: .P2
        !           373: to get
        !           374: .P1
        !           375: Now is the time
        !           376: .P2
        !           377: Notice that
        !           378: .UL //
        !           379: (two adjacent slashes) means ``no characters'', not a blank.
        !           380: There
        !           381: .ul
        !           382: is
        !           383: a difference!
        !           384: (See below for another meaning of
        !           385: .UL // .)

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.