⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vi.in

📁 早期freebsd实现
💻 IN
📖 第 1 页 / 共 5 页
字号:
This will write the contents of the editor's buffer back intothe file you are editing, if you made any changes, and then quit fromthe editor.  You can also end an editorsession by giving the command \fB:q!\fR\s-2CR\s0;\*(dg.FS\*(dg All commands which read from the last display line can also beterminated with a \s-2ESC\s0 as well as an \s-2CR\s0..FEthis is a dangerous but occasionally essentialcommand which ends the editor session and discards all your changes.You need to know about this command in case you change the editor'scopy of a file you wish only to look at.  Be very carefulnot to give this command when you really want to savethe changes you have made..NH 1Moving around in the file.NH 2Scrolling and paging.PPThe editor has a number of commands for moving around in the file.The most useful of these is generated by hitting the control and D keysat the same time, a control-D or `^D'.  We will use this two characternotation for referring to these control keys from now on.  You may havea key labelled `^' on your terminal.  This key will be represented as `\(ua'in this document; `^' is exclusively used as part of the `^x' notationfor control characters.\*(dd.FS\*(dd If you don't have a `^' key on your terminalthen there is probably a key labelled `\(ua'; in any case these charactersare one and the same..FE.PPAs you know now if you tried hitting \fB^D\fR, this command scrolls down inthe file.  The \fBD\fR thus stands for down.  Many editor commands are mnemonicand this makes them much easier to remember.  For instance the commandto scroll up is \fB^U\fR.  Many dumb terminals can't scroll up at all, in whichcase hitting \fB^U\fR clears the screen and refreshes itwith a line which is farther back in the file at the top..PPIf you want to see more of the file below where you are, you canhit \fB^E\fR to expose one more line at the bottom of the screen,leaving the cursor where it is.The command \fB^Y\fR (which is hopelessly non-mnemonic, but next to \fB^U\fRon the keyboard) exposes one more line at the top of the screen..PPThere are other ways to move around in the file; the keys \fB^F\fR and \fB^B\fRmove forward and backward a page,keeping a couple of lines of continuity between screensso that it is possible to read through a file using these rather than\fB^D\fR and \fB^U\fR if you wish..PPNotice the difference between scrolling and paging.  If you are tryingto read the text in a file, hitting \fB^F\fR to move forward a pagewill leave you only a little context to look back at.  Scrolling on theother hand leaves more context, and happens more smoothly.  You can continueto read the text as scrolling is taking place..NH 2Searching, goto, and previous context.PPAnother way to position yourself in the file is by giving the editor a stringto search for.  Type the character \fB/\fR followed by a string of charactersterminated by \s-2CR\s0.  The editor will position the cursorat the next occurrence of this string.Try hitting \fBn\fR to then go to the next occurrence of this string.The character \fB?\fR will search backwards from where you are, and isotherwise like \fB/\fR.\*(dg.FS\*(dg These searches will normally wrap around the end of the file, and thusfind the string even if it is not on a line in the direction you searchprovided it is anywhere else in the file.  You can disable this wraparoundin scans by giving the command \fB:se nowrapscan\fR\s-2CR\s0,or more briefly \fB:se nows\fR\s-2CR\s0..FE.PPIf the search string you give the editor is not present in thefile the editor will printa diagnostic on the last line of the screen, and the cursor will be returnedto its initial position..PPIf you wish the search to match only at the beginning of a line, beginthe search string with an \fB\(ua\fR.  To match only at the end ofa line, end the search string with a \fB$\fR.Thus \fB/\(uasearch\fR\s-2CR\s0 will search for the word `search' atthe beginning of a line, and \fB/last$\fR\s-2CR\s0 searches for theword `last' at the end of a line.*.FS*Actually, the string you give to search for here can be a.I "regular expression"in the sense of the editors.I ex (1)and.I ed (1).If you don't wish to learn about this yet, you can disable this moregeneral facility by doing\fB:se\ nomagic\fR\s-2CR\s0;by putting this command inEXINITin your environment, you can have this always be in effect (moreabout.I EXINITlater.).FE.PPThe command \fBG\fR, when preceded by a number will position the cursorat that line in the file.Thus \fB1G\fR will move the cursor tothe first line of the file.  If you give \fBG\fR no count, then it movesto the end of the file..PPIf you are near the end of the file, and the last line is not at the bottomof the screen, the editor will place only the character `~' on each remainingline.  This indicates that the last line in the file is on the screen;that is, the `~' lines are past the end of the file..PPYou can find out the state of the file you are editing by typing a \fB^G\fR.The editor will show you the name of the file you are editing, the numberof the current line, the number of lines in the buffer, and the percentageof the way through the buffer which you are.Try doing this now, and remember the number of the line you are on.Give a \fBG\fR command to get to the end and then another \fBG\fR commandto get back where you were..PPYou can also get back to a previous position by using the command\fB\(ga\(ga\fR (two back quotes).This is often more convenient than \fBG\fR because it requires no advancepreparation.Try giving a \fBG\fR or a search with \fB/\fR or \fB?\fR and then a\fB\(ga\(ga\fR to get back to where you were.  If you accidentally hit\fBn\fR or any command which moves you far away from a context of interest, youcan quickly get back by hitting \fB\(ga\(ga\fR..NH 2Moving around on the screen.PPNow try just moving the cursor around on the screen.If your terminal has arrow keys (4 or 5 keys with arrowsgoing in each direction) try them and convince yourselfthat they work.If you don't have working arrow keys, you can always use.B h ,.B j ,.B k ,and.B l .Experienced users of.I viprefer these keys to arrow keys,because they are usually right underneath their fingers..PPHit the \fB+\fR key.  Each time you do, notice that the cursoradvances to the next line in the file, at the first non-white positionon the line.  The \fB\-\fR key is like \fB+\fR but goes the other way..PPThese are very common keys for moving up and down lines in the file.Notice that if you go off the bottom or top with these keys then thescreen will scroll down (and up if possible) to bring a line at a timeinto view.  The \s-2RETURN\s0 key has the same effect as the \fB+\fRkey..PP.I Vialso has commands to take you to the top, middle and bottom of the screen.\fBH\fR will take you to the top (home) line on the screen.Try preceding it with anumber as in \fB3H\fR.This will take you to the third line on the screen.Many.I vicommands take preceding numbers and do interesting things with them.Try \fBM\fR,which takes you to the middle line on the screen,and \fBL\fR,which takes you to the last line on the screen.\fBL\fR also takes counts, thus\fB5L\fR will take you to the fifth line from the bottom..NH 2Moving within a line.PPNow try picking a word on some line on the screen, not thefirst word on the line.move the cursor using \s-2RETURN\s0 and \fB\-\fR to be on the line wherethe word is.Try hitting the \fBw\fR key.  This will advance the cursor to thenext word on the line.Try hitting the \fBb\fR key to back up wordsin the line.Also try the \fBe\fR key which advances you to the end of the currentword rather than to the beginning of the next word.Also try \s-2SPACE\s0 (the space bar) which moves right one characterand the \s-2BS\s0 (backspace or \fB^H\fR) key which moves left one character.The key \fBh\fR works as \fB^H\fR does and is useful if you don't havea \s-2BS\s0 key.(Also, as noted just above, \fBl\fR will move to the right.).PPIf the line had punctuation in it you may have noticed thatthat the \fBw\fR and \fBb\fRkeys stopped at each group of punctuation.  You can also go back andforwards words without stopping at punctuation by using \fBW\fR and \fBB\fRrather than the lower case equivalents.  Think of these as bigger words.Try these on a few lines with punctuation to see how they differ fromthe lower case \fBw\fR and \fBb\fR..PPThe word keys wrap around the end of line,rather than stopping at the end.  Try moving to a word on a line belowwhere you are by repeatedly hitting \fBw\fR..NH 2Summary.IP.TSlw(.50i)b a.\fR\s-2SPACE\s0\fP	advance the cursor one position^B	backwards to previous page^D	scrolls down in the file^E	exposes another line at the bottom^F	forward to next page^G	tell what is going on^H	backspace the cursor^N	next line, same column^P	previous line, same column^U	scrolls up in the file^Y	exposes another line at the top+	next line, at the beginning\-	previous line, at the beginning/	scan for a following string forwards?	scan backwardsB	back a word, ignoring punctuationG	go to specified line, last defaultH	home screen lineM	middle screen lineL	last screen lineW	forward a word, ignoring punctuationb	back a worde	end of current wordn	scan for next instance of \fB/\fR or \fB?\fR patternw	word after this word.TE.NH 2View.PPIf you want to use the editor to look at a file,rather than to make changes,invoke it as.I viewinstead of.I vi .This will set the.I readonlyoption which will prevent you fromaccidently overwriting the file..NH 1Making simple changes.NH 2Inserting.PPOne of the most useful commands is the\fBi\fR (insert) command.After you type \fBi\fR, everything you type until you hit \s-2ESC\s0is inserted into the file.Try this now; position yourself to some word in the file and try insertingtext before this word.If you are on an dumb terminal it will seem, for a minute,that some of the characters in your line have been overwritten, but they willreappear when you hit \s-2ESC\s0..PPNow try finding a word which can, but does not, end in an `s'.Position yourself at this word and type \fBe\fR (move to end of word), then\fBa\fR for append and then `s\s-2ESC\s0' to terminate the textual insert.This sequence of commands can be used to easily pluralize a word..PPTry inserting and appending a few times to make sure you understand howthis works; \fBi\fR placing text to the left of the cursor, \fBa\fR tothe right..PPIt is often the case that you want to add new lines to the file you areediting, before or after some specific line in the file.  Find a linewhere this makes sense and then give the command \fBo\fR to create anew line after the line you are on, or the command \fBO\fR to createa new line before the line you are on.  After you create a new line inthis way, text you type up to an \s-2ESC\s0 is inserted on the new line..PPMany related editor commandsare invoked by the same letter key and differ only in that one is givenby a lowercase key and the other is given byan upper case key.  In these cases, theupper case key often differs from the lower case key in its sense ofdirection, withthe upper case key working backward and/or up, while the lower casekey moves forward and/or down..PPWhenever you are typing in text, you can give many lines of input orjust a few characters.To type in more than one line of text,hit a \s-2RETURN\s0 at the middle of your input.  A new line will be createdfor text, and you can continue to type.  If you are on a slowand dumb terminal the editor may choose to wait to redraw thetail of the screen, and will let you type over the existing screen lines.This avoids the lengthy delay which would occur if the editor attemptedto keep the tail of the screen always up to date.  The tail of the screen willbe fixed up, and the missing lines will reappear, when you hit \s-2ESC\s0..PPWhile you are inserting new text, you can use the characters you normally useat the system command level (usually \fB^H\fR or \fB#\fR) to backspaceover the lastcharacter which you typed, and the character which you use to kill input lines(usually \fB@\fR, \fB^X\fR, or \fB^U\fR)to erase the input you have typed on the current line.\*(dg.FS\*(dg In fact, the character \fB^H\fR (backspace) always works to erase thelast input character here, regardless of what your erase character is..FEThe character \fB^W\fRwill erase a whole word and leave you after the space after the previousword; it is useful for quickly backing up in an insert..PPNotice that when you backspace during an insertion the characters youbackspace over are not erased; the cursor moves backwards, and the charactersremain on the display.  This is often useful if you are planning to typein something similar.  In any case the characters disappear when whenyou hit \s-2ESC\s0; if you want to get rid of them immediately, hit an\s-2ESC\s0 and then \fBa\fR again..PPNotice also that you can't erase characters which you didn't insert, and thatyou can't backspace around the end of a line.  If you need to back upto the previous line to make a correction, just hit \s-2ESC\s0 and movethe cursor back to the previous line.  After making the correction youcan return to where you were and use the insert or append command again..NH 2Making small corrections.PPYou can make small corrections in existing text quite easily.Find a single character which is wrong or just pick any character.Use the arrow keys to find the character, orget near the character with the word motion keys and then eitherbackspace (hit the \s-2BS\s0 key or \fB^H\fR or even just \fBh\fR) or \s-2SPACE\s0 (using the space bar)until the cursor is on the character which is wrong.If the character is not needed then hit the \fBx\fP key; this deletesthe character from the file.  It is analogous to the way you \fBx\fPout characters when you make mistakes on a typewriter (except it's notas messy)..PPIf the character

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -