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

25 篇文章 0 订阅
9 篇文章 0 订阅

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值