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

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上,但这个字符最后从删除操作中排除掉了。

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。