[Practical.Vim(2012.9)].Drew.Neil.Tip50 學習摘要

來源:互聯網
上載者:User

標籤: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 學習摘要

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.