?? ae6
字號:
.NHCUT AND PASTE WITH THE EDITOR.PPNow we move on to manipulating pieces of files _individual lines or groups of lines.This is another area where new users seemunsure of themselves..SHFilenames.PPThe first step is to ensure that you know the.UL edcommands for reading and writing files.Of course you can't go very far without knowing.UL rand.UL w .Equally useful, but less well known, is the `edit' command.UL e .Within.UL ed ,.P1e newfile.P2says `I want to edit a new file called.ulnewfile,without leaving the editor.'The.UL ecommand discards whatever you're currently working onand starts over on .ulnewfile.It's exactly the same as if you had quit with the.UL qcommand, then re-entered.UL edwith a new file name,except that if you have a pattern remembered, then a commandlike.UL //will still work..PPIf you enter.UL edwith the command.P1ed file.P2.UL ed remembers the name of the file,and any subsequent.UL e ,.UL ror.UL wcommands that don't contain a filenamewill refer to this remembered file.Thus.P1 2.ta .5i .6i .7ied file1 ... (editing) ...w (writes back in file1)e file2 (edit new file, without leaving editor) ... (editing on file2) ...w (writes back on file2).P2(and so on) does a series of edits on various fileswithout ever leaving.UL edand without typing the name of any file more than once.(As an aside, if you examine the sequence of commands here,you can see why manyUNIXsystems use.UL eas a synonymfor.UL ed .).PPYou can find out the remembered file name at any timewith the.UL fcommand;just type.UL fwithout a file name.You can also change the name of the remembered file name with.UL f ;a useful sequence is.P1ed preciousf junk ... (editing) ....P2which gets a copy of a precious file,then uses.UL fto guarantee that a careless .UL wcommand won't clobber the original..SHInserting One File into Another.PPSuppose you have a file called`memo',and you want the file called`table'to be inserted just after the reference toTable 1.That is, in`memo'somewhere is a line that says.IPTable 1 shows that ....LP`table'has to go there,probably so it will be formattedproperly by.UL nroffor.UL troff .Now what?.PPThis one is easy.Edit`memo',find`Table 1',and add the file`table'right there:.P1ed memo/Table 1/.ft ITable 1 shows that ... [response from ed].ft\&\*.r table.P2The critical line is the last one.As we said earlier, the.UL rcommand reads a file;here you asked for it to be read in right afterline dot.An.UL rcommand without any addressadds lines at the end,so it is the same as.UL $r ..SHWriting out Part of a File.PPThe other side of the coin is writing out part ofthe document you're editing.For example, maybeyou want to split out into a separate filethat table from the previous example,so it can be formatted and tested separately.Suppose that in the file being edited we have.P1\&\*.TS ...[lots of stuff]\&\*.TE.P2which is the way a table is set up for the.UL tblprogram.To isolatethe tablein a separate file called`table',first find the start of the table(the `.TS' line), then write out the interesting part:.P1/^\*e\*.TS/.ft I\&\*.TS [ed prints the line it found].ft R\&\*.,/^\*e\*.TE/w table.P2and the job is done.If you are confident, you can do it all at once with.P1/^\*e\*.TS/;/^\*e\*.TE/w table.P2.PPThe point is that the.UL wcommand canwrite out a group of lines, instead of the whole file.In fact, you can write out a single line if you like;just give one line number instead of two.For example, if you have just typed a horribly complicated lineand you know that it (or something like it) is going to be needed later,then save it _ don't re-type it.In the editor, say.P1a\&...lots of stuff...\&...horrible line...\&\*.\&\*.w tempa\&\*.\*.\*.more stuff\*.\*.\*.\&\*.\&\*.r tempa\&\*.\*.\*.more stuff\*.\*.\*.\&\*..P2This last example is worth studying, to be sure you appreciatewhat's going on..SHMoving Lines Around.PPSuppose you want to move a paragraph from its present position in a paperto the end.How would you do it?As a concrete example, suppose each paragraph in the paperbegins with the formatting command`.PP'.Think about it and write down the details before reading on..PPThe brute force way(not necessarily bad)is to write the paragraph onto a temporary file,delete it from its current position,then read in the temporary file at the end.Assuming that you are sitting on the `.PP' command that beginsthe paragraph, this is the sequence of commands:.P1\&\*.,/^\*e\*.PP/-w temp\&\*.,//-d$r temp.P2That is, from where you are now(`\*.')until one line before the next `\*.PP'(`/^\*e\*.PP/\-')write onto`temp'.Then delete the same lines.Finally, read`temp'at the end..PPAs we said, that's the brute force way.The easier way (often)is to use the.ulmovecommand.UL mthat .UL edprovides _it lets you do the whole set of operationsat one crack,without any temporary file..PPThe .UL mcommandis like many other.UL edcommands in that it takes up to two line numbers in frontthat tell what lines are to be affected.It is also.ulfollowedby a line number that tells where the lines are to go.Thus.P1line1, line2 m line3.P2says to move all the lines between`line1'and`line2'after`line3'.Naturally, any of`line1'etc., can be patterns between slashes,$signs, or other ways to specify lines..PPSuppose again that you're sitting at the first line of theparagraph.Then you can say.P1\&\*.,/^\*e\*.PP/-m$.P2That's all..PPAs another example of a frequent operation,you can reverse the order of two adjacent linesby moving the first oneto after the second.Suppose that you are positioned at the first.Then.P1m+.P2does it.It says to move line dot to after one line after line dot.If you are positioned on the second line,.P1m--.P2does the interchange..PPAs you can see, the.UL mcommand is more succinct and direct thanwriting, deleting and re-reading.When is brute force better anyway?This is a matter of personal taste _do what you have most confidence in.The main difficulty with the.UL mcommandis that if you use patterns to specify both the linesyou are moving and the target,you have to take care that you specify them properly,or you may well not move the lines you thought you did.The result of a botched.UL mcommand can be a ghastly mess.Doing the job a step at a timemakes it easier for you to verify at each stepthat you accomplished what you wanted to.It's also a good idea to issue a .UL wcommandbefore doing anything complicated;then if you goof, it's easy to back upto where you were..SHMarks.PP.UL edprovides a facility for marking a linewith a particular name so you can later reference itby nameregardless of its actual line number.This can be handy for moving lines,and for keeping track of them as they move.The.ulmarkcommand is.UL k ;the command.P1kx.P2marks the current line with the name `x'.If a line number precedes the.UL k ,that line is marked.(The mark name must be a single lower case letter.)Now you can refer to the marked line with the address.P1\(fmx.P2.PPMarks are most useful for moving things around.Find the first line of the block to be moved, and mark itwith.ul\(fma.Then find the last line and mark it with.ul\(fmb.Now position yourself at the place where the stuff is to goand say.P1\(fma,\(fmbm\*..P2.PPBear in mind that only one line can have a particularmark name associated with itat any given time..SHCopying Lines.PPWe mentioned earlier the idea of saving a linethat was hard to type or used often,so as to cut down on typing time.Of course this could be more than one line;then the saving is presumably even greater..PP.UL edprovides another command,called.UL t(for `transfer')for making a copy of a group of one or more linesat any point.This is often easier than writing and reading..PPThe .UL tcommand is identical to the.UL mcommand, except that instead of moving linesit simply duplicates them at the place you named.Thus.P11,$t$.P2duplicates the entire contents that you are editing.A more common use for.UL tis for creating a series of lines that differ only slightly.For example, you can say.P1.ta 1ia\&.......... x ......... (long line)\&\*.t\*. (make a copy)s/x/y/ (change it a bit)t\*. (make third copy)s/y/z/ (change it a bit).P2and so on..SHThe Temporary Escape `!'.PPSometimes it is convenient to be ableto temporarily escape from the editor to dosome other.UXcommand,perhaps one of the file copy or move commandsdiscussed in section 5,without leaving the editor.The `escape' command .UL !provides a way to do this..PPIf you say.P1!any UNIX command.P2your current editing state is suspended,and the.UXcommand you asked for is executed.When the command finishes,.UL edwill signal you by printing another.UL ! ;at that point you can resume editing..PPYou can really do.ulany.UXcommand, including another .UL ed .(This is quite common, in fact.)In this case, you can even do another.UL ! .
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -