📄 vi.in
字号:
Features for editing programs.PPThe editor has a number of commands for editing programs.The thing that most distinguishes editing of programs from editing of textis the desirability of maintaining an indented structure to the body ofthe program. The editor has a.I autoindentfacility for helping you generate correctly indented programs..PPTo enable this facility you can give the command \fB:se ai\fR\s-2CR\s0.Now try opening a new line with \fBo\fR and type some characters on theline after a few tabs. If you now start another line, notice that theeditor supplies white space at the beginning of the line to line it upwith the previous line. You cannot backspace over this indentation,but you can use \fB^D\fR key to backtab over the supplied indentation..PPEach time you type \fB^D\fR you back up one position, normally to an8 column boundary. This amount is settable; the editor has an optioncalled.I shiftwidthwhich you can set to change this value.Try giving the command \fB:se sw=4\fR\s-2CR\s0and then experimenting with autoindent again..PPFor shifting lines in the program left and right, there are operators.B <and.B >.These shift the lines you specify right or left by one.I shiftwidth.Try.B <<and.B >>which shift one line left or right, and.B <Land.B >Lshifting the rest of the display left and right..PPIf you have a complicated expression and wish to see how the parenthesesmatch, put the cursor at a left or right parenthesis and hit \fB%\fR.This will show you the matching parenthesis.This works also for braces { and }, and brackets [ and ]..PPIf you are editing C programs, you can use the \fB[[\fR and \fB]]\fR keysto advance or retreat to a line starting with a \fB{\fR, i.e. a functiondeclaration at a time. When \fB]]\fR is used with an operator it stopsafter a line which starts with \fB}\fR; this is sometimes useful with\fBy]]\fR..NH 2Filtering portions of the buffer.PPYou can run system commands over portions of the buffer using the operator\fB!\fR.You can use this to sort lines in the buffer, or to reformat portionsof the buffer with a pretty-printer.Try typing in a list of random words, one per line and ending themwith a blank line. Back up to the beginning of the list, and then givethe command \fB!}sort\fR\s-2CR\s0. This says to sort the next paragraphof material, and the blank line ends a paragraph..NH 2Commands for editing \s-2LISP\s0.PPIf you are editing a \s-2LISP\s0 program you should set the option.I lispby doing\fB:se\ lisp\fR\s-2CR\s0.This changes the \fB(\fR and \fB)\fR commands to move backward and forwardover s-expressions.The \fB{\fR and \fB}\fR commands are like \fB(\fR and \fB)\fR but don'tstop at atoms. These can be used to skip to the next list, or througha comment quickly..PPThe.I autoindentoption works differently for \s-2LISP\s0, supplying indent to align atthe first argument to the last open list. If there is no such argumentthen the indent is two spaces more than the last level..PPThere is another option which is useful for typing in \s-2LISP\s0, the.I showmatchoption.Try setting it with\fB:se sm\fR\s-2CR\s0and then try typing a `(' some words and then a `)'. Notice that thecursor shows the position of the `(' which matches the `)' briefly. This happens only if the matching `(' is on the screen, and the cursorstays there for at most one second..PPThe editor also has an operator to realign existing lines as though theyhad been typed in with.I lispand.I autoindentset. This is the \fB=\fR operator.Try the command \fB=%\fR at the beginning of a function. This will realignall the lines of the function declaration..PPWhen you are editing \s-2LISP\s0,, the \fB[[\fR and \fR]]\fR advanceand retreat to lines beginning with a \fB(\fR, and are useful for dealingwith entire function definitions..NH 2Macros.PP.I Vihas a parameterless macro facility, which lets you set it up so thatwhen you hit a single keystroke, the editor will act as thoughyou had hit some longer sequence of keys. You can set this up ifyou find yourself typing the same sequence of commands repeatedly..PPBriefly, there are two flavors of macros:.IP a)Ones where you put the macro body in a buffer register, say \fIx\fR.You can then type \fB@x\fR to invoke the macro. The \fB@\fR may be followedby another \fB@\fR to repeat the last macro..IP b)You can use the.I mapcommand from.I vi(typically in your.I EXINIT )with a command of the form:.DS:map \fIlhs\fR \fIrhs\fR\s-2CR\f0.DEmapping.I lhsinto.I rhs.There are restrictions:.I lhsshould be one keystroke (either 1 character or one function key)since it must be entered within one second(unless.I notimeoutis set, in which case you can type it as slowly as you wish,and.I viwill wait for you to finish it before it echoes anything).The.I lhscan be no longer than 10 characters, the.I rhsno longer than 100.To get a space, tab or newline into.I lhsor.I rhsyou should escape them with a \fB^V\fR.(It may be necessary to double the \fB^V\fR if the mapcommand is given inside.I vi,rather than in.I ex.)Spaces and tabs inside the.I rhsneed not be escaped..PPThus to make the \fBq\fR key write and exit the editor, you can givethe command.DS:map q :wq\fB^V^V\fP\s-2CR CR\s0.DEwhich means that whenever you type \fBq\fR, it will be as though youhad typed the four characters \fB:wq\fR\s-2CR\s0.A \fB^V\fR's is needed because without it the \s-2CR\s0 would end the\fB:\fR command, rather than becoming part of the.I mapdefinition.There are two.B ^V 'sbecause from within.I vi ,two.B ^V 'smust be typed to get one.The first \s-2CR\s0 is part of the.I rhs ,the second terminates the : command..PPMacros can be deleted with.DSunmap lhs.DE.PPIf the.I lhsof a macro is ``#0'' through ``#9'', this maps the particular function keyinstead of the 2 character ``#'' sequence. So that terminals withoutfunction keys can access such definitions, the form ``#x'' will mean functionkey.I xon all terminals (and need not be typed within one second.)The character ``#'' can be changed by using a macro in the usual way:.DS:map \fB^V^V^I\fP #.DEto use tab, for example. (This won't affect the.I mapcommand, which still uses.B #,but just the invocation from visual mode..PPThe undo command reverses an entire macro call as a unit,if it made any changes..PPPlacing a `!' after the word.B mapcauses the mapping to applyto input mode, rather than command mode.Thus, to arrange for \fB^T\fP to be the same as 4 spaces in input mode,you can type:.DS:map \fB^T\fP \fB^V\fP\o'b/'\o'b/'\o'b/'\o'b/'.DEwhere.B \o'b/'is a blank.The \fB^V\fP is necessary to prevent the blanks from being taken aswhite space between the.I lhsand.I rhs ..NHWord Abbreviations.PPA feature similar to macros in input mode is word abbreviation.This allows you to type a short word and have it expanded intoa longer word or words.The commands are.B :abbreviateand.B :unabbreviate(\fB:ab\fPand.B :una )and have the same syntax as.B :map .For example:.DS:ab eecs Electrical Engineering and Computer Sciences.DEcauses the word `eecs' to always be changed into thephrase `Electrical Engineering and Computer Sciences'.Word abbreviation is different from macros in thatonly whole words are affected.If `eecs' were typed as part of a larger word, it wouldbe left alone.Also, the partial word is echoed as it is typed.There is no need for an abbreviation to be a single keystroke,as it should be with a macro..NH 2Abbreviations.PPThe editor has a number of shortcommands which abbreviate longer commands which wehave introduced here. You can find these commands easilyon the quick reference card.They often save a bit of typing and you can learn them as convenient..NH 1Nitty-gritty details.NH 2Line representation in the display.PPThe editor folds long logical lines onto many physical lines in the display.Commands which advance lines advance logical lines and will skipover all the segments of a line in one motion. The command \fB|\fR movesthe cursor to a specific column, and may be useful for getting near themiddle of a long line to split it in half. Try \fB80|\fR on a line whichis more than 80 columns long.\*(dg.FS\*(dg You can make long lines very easily by using \fBJ\fR to join togethershort lines..FE.PPThe editor only puts full lines on the display; if there is not enoughroom on the display to fit a logical line, the editor leaves the physicalline empty, placing only an @ on the line as a place holder. When youdelete lines on a dumb terminal, the editor will often just clear thelines to @ to save time (rather than rewriting the rest of the screen.)You can always maximize the information on the screen by giving the \fB^R\fRcommand..PPIf you wish, you can have the editor place line numbers before each lineon the display. Give the command \fB:se nu\fR\s-2CR\s0 to enablethis, and the command \fB:se nonu\fR\s-2CR\s0 to turn it off.You can have tabs represented as \fB^I\fR and the ends of lines indicatedwith `$' by giving the command \fB:se list\fR\s-2CR\s0;\fB:se nolist\fR\s-2CR\s0 turns this off..PPFinally, lines consisting of only the character `~' are displayed whenthe last line in the file is in the middle of the screen. These representphysical lines which are past the logical end of file..NH 2Counts.PPMost.I vicommands will use a preceding count to affect their behavior in some way.The following table gives the common ways in which the counts are used:.DS.TSl lb.new window size : / ? [[ ]] \` \'scroll amount ^D ^Uline/column number z G |repeat effect \fRmost of the rest\fP.TE.DE.PPThe editor maintains a notion of the current default window size.On terminals which run at speeds greater than 1200 baudthe editor uses the full terminal screen.On terminals which are slower than 1200 baud(most dialup lines are in this group)the editor uses 8 lines as the default window size.At 1200 baud the default is 16 lines..PPThis size is the size used when the editor clears and refills the screenafter a search or other motion moves far from the edge of the current window.The commands which take a new window size as count all often cause thescreen to be redrawn. If you anticipate this, but do not need as largea window as you are currently using, you may wish to change the screensize by specifying the new size before these commands.In any case, the number of lines used on the screen will expand if youmove off the top with a \fB\-\fR or similar command or off the bottomwith a command such as \s-2RETURN\s0 or \fB^D\fR.The window will revert to the last specified size the next time it iscleared and refilled.\*(dg.FS\*(dg But not by a \fB^L\fR which just redraws the screen as it is..FE.PPThe scroll commands \fB^D\fR and \fB^U\fR likewise remember the amountof scroll
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -