码迷,mamicode.com
首页 > 系统相关 > 详细

[Practical.Vim(2012.9)].Drew.Neil.Tip50 学习摘要

时间:2015-04-14 00:45:54      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:search   vim   

Search to Navigate

The character search commands ( f{char} , t{char} , and so on) are fast and lightweight, but they have limitations. They can only search for a single character at a time, and they can only operate within the current line.
字符搜索命令f{char} , t{char} 等,非常快捷,但是这些命令一次只能搜索一个字符,而且只能在当前行中操作。
Suppose that we want to position our cursor on the word “takes ” in this sample:
假设我们在下面文本中要定位词语“takes”
技术分享
我们可以用搜索命令 /takes
Operate with a Search Motion
We ’re not limited to using the search command in Normal mode. We can use it from Visual and Operator-Pending modes just as well to do real work. For example, suppose that we wanted to delete the text “takes time but eventually” from this phrase:
搜索命令的使用方法不仅仅局限于此。我们可以在Visual和Operator Pending模式中使用来做一些其他有用的工作。比如,假设我们从下面文本中想要删除“takes time but eventually”
技术分享
To begin with, we press v to switch to Visual mode. Then we can extend the selection by searching for the short “ge ” string, which puts the cursor where we want it in a single bound. Well, almost—we have an off-by-one error. The selection includes the “g” at the start of the word, but we don ’t want to delete that. We ’ll use h to back up one character. Then, having defined our selection, we ’ll delete it with the d command.
首先,我们输入v切换到Visual模式,然后通过搜索“ge”字符串拓展选择范围,光标停留在了gets的第一个字符g上。但是有一个问题,选择范围的最后一个字符包含了字符g,我们并不要删除它,所以再用命令h退后一个字符。最后,再使用d命令删除这个范围内的字符。
Here ’s an even quicker way of doing the same thing:
下面介绍的是一个更加简单的方法
技术分享

Here, we use the /ge search motion to tell the d{motion} command what to delete. The search command is an exclusive motion. That means that even though our cursor ends up on the “g” at the start of the word “gets, ” that character is excluded from the delete operation
这里,首先将光标定位在 takes上,然后利用/ge搜索命令告诉d{motion}命令删除到哪里。这个搜索操作是排除运动,意味着即使最后光标停留在gets的第一个字符g上,但这个字符最后从删除操作中排除掉了。

[Practical.Vim(2012.9)].Drew.Neil.Tip50 学习摘要

标签:search   vim   

原文地址:http://blog.csdn.net/wdy_yx/article/details/45033797

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!