Vim常用操作-快速刪除括號中內容。

吳佰清發表於2017-04-25

如果你和我一樣,希望擁有眾多工具,發揮工具最大執行效率,讓工作事半功倍的話,我推薦你來使用下 Vim。

剛接觸Vim 會覺得它的學習曲線非常陡峭,要記住很多命令,操作太複雜。所以這個系列的分享,不會教你怎麼

配置它,而是教你怎麼快速的掌握它。

 

學不會就不要繼續學了,直接拿來用就好了。

 

接下來我們要實現這種效果,快速的刪除括號中的內容。

 

操作步驟:

1. 按 ESC 進入 Normal 模式,通過 h 左、j 下、k 上、l 右 來控制游標,把游標移動到括

號中。

2. 連續按 di( 就可以把括號中的內容刪除了。

剛才連續按下的快捷鍵,代表的意思是 delete all content inside ( 所以結果字串為 ()

 

更多案例:

比如說有這麼個字串 "testdfat",假設游標停留在第一個 t 位置。

di":delete all content inside ",結果字串為""

dta:delete all content to a,結果字串為"at"

dfa:delete all content from current location, until a is found,結果字串為"t"

 

高手進階:

i 表示 inside,開啟 Vim 後,執行 :help object-select 可以看詳細介紹。

This is a series of commands that can only be used while in Visual mode or
after an operator. The commands that start with "a" select "a"n object
including white space, the commands starting with "i" select an "inner" object
without white space, or just the white space. Thus the "inner" commands
always select less text than the "a" commands.
These commands are {not in Vi}.
These commands are not available when the +textobjects feature has been
disabled at compile time.
Also see gn and gN, operating on the last search pattern.

 

相關學習:

Vim 模式:http://www.cnblogs.com/zeushuang/archive/2012/11/16/2772830.html

相關文章