Plaintext Text Objects
Vim provides text objects for the three building blocks of plaintext:
- words
- sentences
- paragraphs.
Words
aw
a word (includes surrounding white space)
包括單詞周圍的空格
iw
inner word (does not include surrounding white space)
不包括單詞周圍的空格
aw, iw 和 w 的區(qū)別
The motion w may seem similar to the text object aw. The difference is in the allowed cursor position.
w 和 aw, iw 的區(qū)別體現(xiàn)在于光標(biāo)位置上.
For example, to delete a word using dw, the cursor must be at the start of the word, any other position would delete only part of the word;
however, daw allows the cursor to be at any position in the word.
要使用 dw 來完整刪除一個單詞, 光標(biāo)必須在單詞的開頭. 對應(yīng)的, 使用 daw 來刪除一個單詞的時候, 光標(biāo)可以在單詞上的任何一個位置. daw 可以刪除單詞和單詞周圍的空白符, 而 diw 只會刪除單詞自身
W
一段連續(xù)的文本 (直到空白符為止)
Sentences
as
a sentence
is
inner sentence
as, is 和 ( )
Like aw, as offers the same cursor position advantage over its motion counterparts ( )
To operate on the entire previous sentence ( requires the cursor to be at the end of the sentence; to operate on the entire next sentence ) requires your cursor to be at the start of the sentence.
as 和 is的區(qū)別在于, as 對應(yīng)的文本包括了句子前后的空白符.
Paragraphs
ap
a paragraph
ip
inner paragraph
ap, ip 對比 { }
同上述的 aw,iw, as,is, ap,ip 的優(yōu)點在于不需要移動光標(biāo)到段首就可以刪除整個段落.
Programming Language Text Objects
Vim provides several text objects based on common programming language constructs.
Other Text Objects
Strings
a"
a double quoted string
i"
inner double quoted string
a'
a single quoted string
i'
inner single quoted string
a`
a back quoted string
i`
inner back quoted string
ps: these command is effective against the first corresponded phrase in the line.
Parentheses ( )
a)
a parenthesized block
一個被括號包圍的塊
i)
inner parenthesized block
括號內(nèi)部的塊
同時也可以用 b 來表示 ( 和 ), 即 ab, ib
對比 ( )和a), i)
- ( ) 表示的是句子的首尾, 而 a), i) 表示的是被 ( ) 包圍的文本.
d( , d) 會從光標(biāo)位置開始刪除到句首/句尾 - da), di) 只有當(dāng)光標(biāo)在內(nèi)括號內(nèi)才會生效, 會刪除括號內(nèi)的內(nèi)容.
生效條件 ( 適用于 (), [], {} ): - a) , i) 或 ab, ib 僅當(dāng)光標(biāo)在括號體中才能生效
使用 % 在括號之間移動
The % motion is used to move cursor to the first parentheses (bracing character) in the line.
用于將光標(biāo)移動至當(dāng)前行的第一個括號/包圍符號, 以及在這對括號之間切換光標(biāo)位置.
d%
用于刪除從光標(biāo)到括號(包圍符號) 之間的文本.
對比 % 和 a)
1.a) 和 i) 更加便利, 用于選中 ( ) 中的文本, 但是只有當(dāng)光標(biāo)在 括號中才會生效.
- 而 % 可以將光標(biāo)跳轉(zhuǎn)到 該行的括號上, 或者是在兩個 ( ) 之間切換光標(biāo)位置.
- da) 會刪除本行的第一個括號間的內(nèi)容.
- d% 會刪除從光標(biāo)的位置開始直到第一個括號結(jié)束之間的內(nèi)容.
Brackets [ ]
a]
a bracketed block
i]
inner bracketed block
用法同括號( )
The % movement can also be with []. However, it has the same limited flexibility when using it with ().
Braces { }
a}
a brace block
i}
inner brace block
% 也對 { } 生效.
a} , i} 也可以用 aB, iB 替代.
Markup Language Tag
tag content selection:
cursor need to be arounded by a pair of tags.
at
a tag block (tag included)
整個標(biāo)簽和標(biāo)簽包圍的文本
it
inner tag block (tag excluded)
被標(biāo)簽包圍的文本
tag selection:
cursor need to be inside tag itself
da< 或 da>
刪除這個tag
di< 或 di>
刪除tag中的文本