📄 e5
字号:
.SHChange and Insert \- ``c'' and ``i''.PPThis section discusses the.ulchangecommand.P1c.P2which is used to changeor replace a group of one or more lines,and the.ulinsertcommand.P1i.P2which is used for inserting a group of one or more lines..PP``Change'', written as.P1c.P2is used to replace a number of lines with different lines, whichare typed in at the terminal.For example,to change lines.UL .+1through.UL $to something else, type.P1\&.+1,$c\&. . . \fItype the lines of text you want here\fP . . .\*..P2The lines you type between the.UL ccommand andthe .UL .will take the place of the original lines betweenstart line and end line.This is most useful in replacing a lineor several lines which have errors in them..PPIf only one line is specified in the.UL ccommand, then justthat line is replaced.(You can type in as many replacement lines as you like.)Noticethe use of.UL .to end theinput \- this works just like the.UL .in the append commandand must appear by itself on a new line.If no line number is given, line dot is replaced.The value of dot is set to the last line you typed in..PP``Insert'' is similar to append \- for instance.P1/string/i\&. . . \fItype the lines to be inserted here\fP . . .\*..P2will insert the given text.ulbeforethe next line that contains ``string''.The text between.UL iand.UL .is.ulinserted beforethe specified line.If no line number is specified dot is used.Dot is set to the last line inserted..SHExercise 7:.PP``Change'' is rather like a combination ofdelete followed by insert.Experiment to verify that.P1\fIstart, end\fP di.ul\&. . . text . . .\*..P2is almost the same as.P1\fIstart, end\fP c.ul\&. . . text . . .\*..P2These are not.ulpreciselythe sameif line.UL $gets deleted.Check this out.What is dot?.PPExperiment with.UL aand.UL i ,to see that they aresimilar, but not the same.You will observe that.P1\fIline\(hynumber\fP a\&. . . \fItext\fP . . .\*..P2appends.ulafterthe given line, while.P1\fIline\(hynumber\fP i\&. . . \fItext\fP . . .\*..P2inserts.ulbeforeit.Observe that if no line number is given,.UL iinserts before line dot, while .UL aappendsafter line dot..SHMoving text around: the ``m'' command.PPThe move command .UL mis used for cutting and pasting \-it lets you move a group of linesfrom one place to another in the buffer.Suppose you want to put the first three lines of the buffer at the end instead.You could do it by saying:.P11,3w temp$r temp1,3d.P2(Do you see why?)but you can do it a lot easier with the .UL mcommand:.P11,3m$.P2The general case is.P1\fIstart line, end line\fP m \fIafter this line\fP.P2Notice that there is a third line to be specified \-the place where the moved stuff gets put.Of course the lines to be moved can be specifiedby context searches;if you had.P1First paragraph\&. . .end of first paragraph.Second paragraph\&. . .end of second paragraph..P2you could reverse the two paragraphs like this:.P1/Second/,/end of second/m/First/\-1.P2Notice the.UL \-1 :the moved text goes.ulafterthe line mentioned.Dot gets set to the last line moved..SHThe global commands ``g'' and ``v''.PPThe.ulglobalcommand.UL gis used to execute one or more .uledcommands on all those lines in the bufferthat match some specified string.For example.P1g/peling/p.P2prints all lines that contain.UL peling .More usefully,.P1g/peling/s//pelling/gp.P2makes the substitution everywhere on the line,then prints each corrected line.Compare this to.P11,$s/peling/pelling/gp.P2which only prints the last line substituted.Another subtle difference is thatthe.UL gcommanddoes not give a.UL ?if.UL pelingis not foundwhere the.UL scommand will..PPThere may be several commands(including.UL a ,.UL c ,.UL i ,.UL r ,.UL w ,but not.UL g );in that case,every line except the last must end with a backslash.UL \e :.P1g/xxx/\*.-1s/abc/def/\\\&\*.+2s/ghi/jkl/\\\&\*.-2,\*.p.P2makes changes in the lines before and after each linethat contains.UL xxx ,then prints all three lines..PPThe.UL vcommand is the same as.UL g ,except that the commands are executed on every linethat does.ulnotmatch the string following.UL v :.P1v/ /d.P2deletes every line that does not contain a blank.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -