vi笔记4——vi之超越基础

来源:互联网 发布:mac屏幕涂层脱落原因 编辑:程序博客网 时间:2024/06/05 04:15

vi笔记4——vi之超越基础

VI超越基础主要包含以下内容:

Beyond the Basics
It covers:
• Descriptions of additional editing facilities, with a review of the general command
form
• Additional ways to enter vi
• Making use of buffers that store yanks and deletions
• Marking your place in a file


相关命令说明如下:

More Command CombinationsTable 4-1. More editing commandsChange Delete Copy From cursor to...cH   dH  yH  Top of screencL  dL  yL Bottom of screenc+ d+  y+  Next linec5|  d5| y5| Column 5 of current line2c)  2d)  2y)  Second sentence followingc{  d{  y{  Previous paragraphc/pattern  d/pattern   y/pattern  Patterncn  dn  yn  Next patterncG  dG  yG  End of filec13G  d13G  y13G  Line number 13部分规律(number)(command)(text object)number is the optional numeric argument. command in this case is one of c, d, or y. text object is a movement command.Advancing to a Specific Place$ vi +n fileOpens file at line number n.$ vi + fileOpens file at last line.$ vi +/pattern fileOpens file at the first occurrence of pattern.注意:If you include spaces in the pattern, you must enclose the wholepattern within single or double quotes:†+/"you make"or escape the space with a backslash:+/you\ make当查找的模式中含有空格的时候,建议直接使用双引号,反斜杠加空格(/ )在windowsgvim中不起作用Using +/pattern is helpful if you have to leave an editing session before you’re finished.You can mark your place by inserting a pattern such as ZZZ or HERE.Then, when you return to the file, all you have to remember is /ZZZ or /HERE.Read-Only ModeTo look at a file in read-only mode, enter either:$ vi -R fileor:$ view fileYou can override read-only mode by adding an exclamation point to thewrite command::w!or::wqRecovering a Buffer$ ex -ror:$ vi -ryou will get a list of any files that the system has saved.$ vi -r practice  --恢复practice的bufferYou can force the system to preserve your buffer even when there is not a crash by using the command :pre (short for :preserve). Making Use of Buffersd x y content is saved to buffers,we can use p or P to put the text back.vi also allows you to place yanks (copied text) into buffers identified by letters. You can fill up to 26 (a–z) buffers with yanked text and restore that text with a put command at any time in your editing session.Recovering DeletionsTo recover a deletion, type " (double quote), identify the buffered text by number, then give the put command. To recover your second-to-last deletion from buffer 2, type:"2p"np 即为恢复倒数第n次的内容"1pu.u.  --依次增加地恢复删除的内容,u(撤销).(点为重复),每重复一次其对应的缓存数字会依次增加一个(若"np中的n为1,则增加到2,若"np中的n为2,则依次增加为3、4、5 etc)Yanking to Named BuffersTo yank into a named buffer, precede the yank command with a double quote (") and the character for the name of the buffer you want to load. For example:"dyy Yank current line into buffer d."a7yy Yank next seven lines into buffer a.After loading the named buffers and moving to the new position, use p or P to put the text back:"dP Put the contents of buffer d before cursor."ap Put the contents of buffer a after cursor.对于复制的内容一般依次保存在9个默认的buffer中,为了方便使用,我们可以将其保存在固定名称的buffer中,一般以小写的a-z命名。将缓冲区命名的好处是可以将命名的缓存粘贴至vi中其它文件中。"a5dd  -- Delete five lines into buffer a对于特定名称的缓存,可以用以下非固定的方式向其中填充内容"zd)Delete from cursor to end of current sentence and save in buffer z.2)Move two sentences further on."Zy)Add the next sentence to buffer zMarking Your PlaceIn command mode:mxMarks the current position with x (x can be any letter). (The original vi allows only lowercase letters. Vim distinguishes between uppercase and lowercase letters.)'x(Apostrophe.) Moves the cursor to the first character of the line marked by x.`x(Backquote.) Moves the cursor to the character marked by x.``(Backquotes.) Returns to the exact position of the previous mark or context after a move.''(Apostrophes.) Returns to the beginning of the line of the previous mark or context.注意:Mark只用于当前vi会话中,并不保存在文件中,因此只要退出就失效了Review of vi Buffer and Marking CommandsTable 4-2 summarizes the command-line options common to all versions of vi. Tables4-3 and 4-4 summarize the buffer and marking commands.Table 4-2. Command-line optionsOption Meaning+n file Open file at line number n.+ file Open file at last line.+/pattern file Open file at first occurrence of pattern (traditional version of POSIX -c).-c command file Run command after opening file; usually a line number or search (POSIX version of +).-R Operate in read-only mode (same as using view instead of vi).-r Recover files after a crash.Table 4-3. Buffer namesBuffer names Buffer use1–9 The last nine deletions, from most to least recent.a–z Named buffers for you to use as needed. Uppercase letters append to the buffer.Table 4-4. Buffer and marking commandsCommand Meaning"b command Do command with buffer b.mx Mark current position with x.'x Move cursor to first character of line marked by x.`x Move cursor to character marked by x.`` Return to exact position of previous mark or context.'' Return to beginning of the line of previous mark or context.

以上是学习vim时候整理的一些要点,分享此处以供学习!

对于一些想深入学习vi的人群,可以参考以下图书:Learning.the.vi.and.Vim.Editors.7th

下载链接:http://download.csdn.net/detail/u011127242/9617946
1 0
原创粉丝点击