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

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 Combinations
Table 4-1. More editing commands
Change 		Delete 		Copy 		From cursor to...
cH 	  	dH 	 	yH  	Top of screen
cL  	dL  	yL 		Bottom of screen
c+ 		d+  	y+ 	 	Next line
c5|  	d5| 	y5| 	Column 5 of current line
2c)  	2d)  	2y)  	Second sentence following
c{  	d{ 	 	y{  	Previous paragraph
c/pattern 	 	d/pattern  	 	y/pattern 		 Pattern
cn  	dn  	yn  	Next pattern
cG  	dG  	yG  	End of file
c13G  	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 file
Opens file at line number n.
$ vi + file
Opens file at last line.
$ vi +/pattern file
Opens file at the first occurrence of pattern.
注意:If you include spaces in the pattern, you must enclose the whole
pattern 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 Mode
To look at a file in read-only mode, enter either:
$ vi -R file
or:
$ view file
You can override read-only mode by adding an exclamation point to the
write command:
:w!
or:
:wq

Recovering a Buffer
$ ex -r
or:
$ vi -r
you will get a list of any files that the system has saved.
$ vi -r practice  --恢复practice的buffer
You 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 Buffers
d 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 Deletions
To 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 Buffers
To 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 z

Marking Your Place
In command mode:
mx
Marks 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 Commands
Table 4-2 summarizes the command-line options common to all versions of vi. Tables
4-3 and 4-4 summarize the buffer and marking commands.
Table 4-2. Command-line options
Option 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 names
Buffer names Buffer use
1–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 commands
Command 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
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

昕光xg

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值