📄 vi.in
字号:
.PPYou can edit a different file without leaving the editor by giving thecommand \fB:e\fR\ \fIname\fR\s-2CR\s0. If you have not written outyour file before you try to do this, then the editor will tell you this,and delay editing the other file. You can then give the command\fB:w\fR\s-2CR\s0 to save your work and then the \fB:e\fR\ \fIname\fR\s-2CR\s0command again, or carefully give the command \fB:e!\fR\ \fIname\fR\s-2CR\s0,which edits the other file discarding the changes you have made to thecurrent file.To have the editor automatically save changes,include.I "set autowrite"in your EXINIT,and use \fB:n\fP instead of \fB:e\fP..NH 2Escaping to a shell.PPYou can get to a shell to execute a single command by giving a.I vicommand of the form \fB:!\fIcmd\fR\s-2CR\s0.The system will run the single command.I cmdand when the command finishes, the editor will ask you to hit a \s-2RETURN\s0to continue. When you have finished looking at the output on the screen,you should hit \s-2RETURN\s0 and the editor will clear the screen andredraw it. You can then continue editing.You can also give another \fB:\fR command when it asks you for a \s-2RETURN\s0;in this case the screen will not be redrawn..PPIf you wish to execute more than one command in the shell, then you cangive the command \fB:sh\fR\s-2CR\s0.This will give you a new shell, and when you finish with the shell, endingit by typing a \fB^D\fR, the editor will clear the screen and continue..PPOn systems which support it, \fB^Z\fP will suspend the editorand return to the (top level) shell.When the editor is resumed, the screen will be redrawn..NH 2Marking and returning.PPThe command \fB\(ga\(ga\fR returned to the previous placeafter a motion of the cursor by a command such as \fB/\fR, \fB?\fR or\fBG\fR. You can also mark lines in the file with single letter tagsand return to these marks later by naming the tags. Try marking thecurrent line with the command \fBm\fR\fIx\fR, where you should pick someletter for \fIx\fR, say `a'. Then move the cursor to a different line(any way you like) and hit \fB\(gaa\fR. The cursor will return to theplace which you marked.Marks last only until you edit another file..PPWhen using operators such as.B dand referring to marked lines, it is often desirable to delete whole linesrather than deleting to the exact position in the line marked by \fBm\fR.In this case you can use the form \fB\(aa\fR\fIx\fR rather than\fB\(ga\fR\fIx\fR. Used without an operator, \fB\(aa\fR\fIx\fR will move tothe first non-white character of the marked line; similarly \fB\(aa\(aa\fRmoves to the first non-white character of the line containing the previouscontext mark \fB\(ga\(ga\fR..NH 2Adjusting the screen.PPIf the screen image is messed up because of a transmission error to yourterminal, or because some program other than the editor wrote outputto your terminal, you can hit a \fB^L\fR, the \s-2ASCII\s0 form-feedcharacter, to cause the screen to be refreshed..PPOn a dumb terminal, if there are @ lines in the middle of the screenas a result of line deletion, you may get rid of these lines by typing\fB^R\fR to cause the editor to retype the screen, closing up these holes..PPFinally, if you wish to place a certain line on the screen at the topmiddle or bottom of the screen, you can position the cursor to that line,and then give a \fBz\fR command.You should follow the \fBz\fR command with a \s-2RETURN\s0 if you wantthe line to appear at the top of the window, a \fB.\fR if you want itat the center, or a \fB\-\fR if you want it at the bottom..NH 1Special topics.NH 2Editing on slow terminals.PPWhen you are on a slow terminal, it is important to limit the amountof output which is generated to your screen so that you will not sufferlong delays, waiting for the screen to be refreshed. We have alreadypointed out how the editor optimizes the updating of the screen duringinsertions on dumb terminals to limit the delays, and how the editor eraseslines to @ when they are deleted on dumb terminals..PPThe use of the slow terminal insertion mode is controlled by the.I slowopenoption. You can force the editor to use this mode even on faster terminalsby giving the command \fB:se slow\fR\s-2CR\s0. If your system is sluggishthis helps lessen the amount of output coming to your terminal.You can disable this option by \fB:se noslow\fR\s-2CR\s0..PPThe editor can simulate an intelligent terminal on a dumb one. Trygiving the command \fB:se redraw\fR\s-2CR\s0. This simulation generatesa great deal of output and is generally tolerable only on lightly loadedsystems and fast terminals. You can disable this by giving the command \fB:se noredraw\fR\s-2CR\s0..PPThe editor also makes editing more pleasant at low speed by startingediting in a small window, and letting the window expand as you edit.This works particularly well on intelligent terminals. The editor canexpand the window easily when you insert in the middle of the screenon these terminals. If possible, try the editor on an intelligent terminalto see how this works..PPYou can control the size of the window which is redrawn each time thescreen is cleared by giving window sizes as argument to the commandswhich cause large screen motions:.DS.B ": / ? [[ ]] \(ga \(aa".DEThus if you are searching for a particular instance of a common stringin a file you can precede the first search command by a small number,say 3, and the editor will draw three line windows around each instanceof the string which it locates..PPYou can easily expand or contract the window, placing the current lineas you choose, by giving a number on a \fBz\fR command, after the \fBz\fRand before the following \s-2RETURN\s0, \fB.\fR or \fB\-\fR. Thus thecommand \fBz5.\fR redraws the screen with the current line in the centerof a five line window.\*(dg.FS\*(dg Note that the command \fB5z.\fR has an entirely different effect,placing line 5 in the center of a new window..FE.PPIf the editor is redrawing or otherwise updating large portions of thedisplay, you can interrupt this updating by hitting a \s-2DEL\s0 or \s-2RUB\s0as usual. If you do this you may partially confuse the editor aboutwhat is displayed on the screen. You can still edit the text onthe screen if you wish; clear up the confusionby hitting a \fB^L\fR; or move or search again, ignoring thecurrent state of the display..PPSee section 7.8 on \fIopen\fR mode for another way to use the.I vicommand set on slow terminals..NH 2Options, set, and editor startup files.PPThe editor has a set of options, some of which have been mentioned above.The most useful options are given in the following table..KF.TSlb lb lb lbl l l a.Name Default Description_autoindent noai Supply indentation automaticallyautowrite noaw Automatic write before \fB:n\fR, \fB:ta\fR, \fB^\(ua\fR, \fB!\fRignorecase noic Ignore case in searchinglisp nolisp \fB( { ) }\fR commands deal with S-expressionslist nolist Tabs print as ^I; end of lines marked with $magic nomagic The characters . [ and * are special in scansnumber nonu Lines are displayed prefixed with line numbersparagraphs para=IPLPPPQPbpP LI Macro names which start paragraphsredraw nore Simulate a smart terminal on a dumb onesections sect=NHSHH HU Macro names which start new sectionsshiftwidth sw=8 Shift distance for <, > and input \fB^D\fP and \fB^T\fRshowmatch nosm Show matching \fB(\fP or \fB{\fP as \fB)\fP or \fB}\fR is typedslowopen slow Postpone display updates during insertsterm dumb The kind of terminal you are using..TE.KE.PPThe options are of three kinds: numeric options, string options, andtoggle options. You can set numeric and string options by a statementof the form.DS\fBset\fR \fIopt\fR\fB=\fR\fIval\fR.DEand toggle options can be set or unset by statements of one of the forms.DS\fBset\fR \fIopt\fR\fBset\fR \fBno\fR\fIopt\fR.DEThese statements can be placed in your EXINIT in your environment,or given while you are running.I viby preceding them with a \fB:\fR and following them with a \s-2CR\s0..PPYou can get a list of all options which you have changed by thecommand \fB:set\fR\s-2CR\s0, or the value of a single option by thecommand \fB:set\fR \fIopt\fR\fB?\fR\s-2CR\s0.A list of all possible options and their values is generated by\fB:set all\fP\s-2CR\s0.Set can be abbreviated \fBse\fP.Multiple options can be placed on one line, e.g.\fB:se ai aw nu\fP\s-2CR\s0..PPOptions set by the \fBset\fP command only lastwhile you stay in the editor.It is common to want to have certain options set whenever youuse the editor.This can be accomplished by creating a list of \fIex\fP commands\*(dg.FS\*(dgAll commands which start with.B :are \fIex\fP commands..FEwhich are to be run every time you start up \fIex\fP, \fIedit\fP,or \fIvi\fP.A typical list includes a \fBset\fP command, and possibly a few\fBmap\fP commands.Since it is advisable to get these commands on one line, they canbe separated with the | character, for example:.DS\fBset\fP ai aw terse|\fBmap\fP @ dd|\fBmap\fP # x.DEwhich sets the options \fIautoindent\fP, \fIautowrite\fP, \fIterse\fP,(the.B setcommand),makes @ delete a line,(the first.B map ),and makes # delete a character,(the second.B map ).(See section 6.9 for a description of the \fBmap\fP command)This string should be placed in the variable EXINIT in your environment.If you use the shell \fIcsh\fP,put this line in the file.I .loginin your home directory:.DSsetenv EXINIT \(aa\fBset\fP ai aw terse|\fBmap\fP @ dd|\fBmap\fP # x\(aa.DEIf you use the standard shell \fIsh\fP,put these lines in the file.I .profilein your home directory:.DSEXINIT=\(aa\fBset\fP ai aw terse|\fBmap\fP @ dd|\fBmap\fP # x\(aaexport EXINIT.DEOf course, the particulars of the line would depend on which optionsyou wanted to set..NH 2Recovering lost lines.PPYou might have a serious problem if you delete a number of lines and thenregret that they were deleted. Despair not, the editor saves the last9 deleted blocks of text in a set of numbered registers 1\-9.You can get the \fIn\fR'th previous deleted text back in your file bythe command"\fR\fIn\fR\|\fBp\fR.The "\fR here says that a buffer name is to follow,\fIn\fR is the number of the buffer you wish to try(use the number 1 for now),and.B pis the put command, which puts text in the buffer after the cursor.If this doesn't bring back the text you wanted, hit.B uto undo this and then\fB\&.\fR(period)to repeat the put command.In general the\fB\&.\fRcommand will repeat the last change you made.As a special case, when the last command refers to a numbered text buffer,the \fB.\fR command increments the number of the buffer before repeatingthe command. Thus a sequence of the form.DS\fB"1pu.u.u.\fR.DEwill, if repeated long enough, show you all the deleted text which hasbeen saved for you.You can omit the.B ucommands here to gather up all this text in the buffer, or stop after any\fB\&.\fR command to keep just the then recovered text.The command.B Pcan also be used rather than.B pto put the recovered text before rather than after the cursor..NH 2Recovering lost files.PPIf the system crashes, you can recover the work you were doingto within a few changes. You will normally receive mail when you nextlogin giving you the name of the file which has been saved for you. You should then change to the directory where you were when the systemcrashed and give a command of the form:.DS% \fBvi \-r\fR \fIname\fR.DEreplacing \fIname\fR with the name of the file which you were editing.This will recover your work to a point near where you left off.\*(dg.FS\*(dg In rare cases, some of the lines of the file may be lost. Theeditor will give you the numbers of these lines and the text of the lineswill be replaced by the string `LOST'. These lines will almost alwaysbe among the last few which you changed. You can either choose to discardthe changes which you made (if they are easy to remake) or to replacethe few lost lines by hand..FE.PPYou can get a listing of the files which are saved for you by givingthe command:.DS% \fBvi \-r\fR.DEIf there is more than one instance of a particular file saved, the editorgives you the newest instance each time you recover it. You can thusget an older saved copy back by first recovering the newer copies..PPFor this feature to work,.I vimust be correctly installed by a super user on your system,and the.I mailprogram must exist to receive mail.The invocation ``\fIvi -r\fP'' will not always list all saved files,but they can be recovered even if they are not listed..NH 2Continuous text input.PPWhen you are typing in large amounts of text it is convenient to havelines broken near the right margin automatically. You can cause thisto happen by giving the command\fB:se wm=10\fR\s-2CR\s0.This causes all lines to be broken at a space at least 10 columnsfrom the right hand edge of the screen..PPIf the editor breaks an input line and you wish to put it back togetheryou can tell it to join the lines with \fBJ\fR. You can give \fBJ\fRa count of the number of lines to be joined as in \fB3J\fR to join 3lines. The editor supplies white space, if appropriate,at the juncture of the joinedlines, and leaves the cursor at this white space.You can kill the white space with \fBx\fR if you don't want it..NH 2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -