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 的区别
The motion w may seem similar to the text object aw. The difference is in the allowed cursor position.
w 和 aw, iw 的区别体现在于光标位置上.
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 来完整删除一个单词, 光标必须在单词的开头. 对应的, 使用 daw 来删除一个单词的时候, 光标可以在单词上的任何一个位置. daw 可以删除单词和单词周围的空白符, 而 diw 只会删除单词自身
W
一段连续的文本 (直到空白符为止)
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的区别在于, as 对应的文本包括了句子前后的空白符.
Paragraphs
ap
a paragraph
ip
inner paragraph
ap, ip 对比 { }
同上述的 aw,iw, as,is, ap,ip 的优点在于不需要移动光标到段首就可以删除整个段落.
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
括号内部的块
同时也可以用 b 来表示 ( 和 ), 即 ab, ib
对比 ( )和a), i)
- ( ) 表示的是句子的首尾, 而 a), i) 表示的是被 ( ) 包围的文本.
d( , d) 会从光标位置开始删除到句首/句尾 - da), di) 只有当光标在内括号内才会生效, 会删除括号内的内容.
生效条件 ( 适用于 (), [], {} ): - a) , i) 或 ab, ib 仅当光标在括号体中才能生效
使用 % 在括号之间移动
The % motion is used to move cursor to the first parentheses (bracing character) in the line.
用于将光标移动至当前行的第一个括号/包围符号, 以及在这对括号之间切换光标位置.
d%
用于删除从光标到括号(包围符号) 之间的文本.
对比 % 和 a)
1.a) 和 i) 更加便利, 用于选中 ( ) 中的文本, 但是只有当光标在 括号中才会生效.
- 而 % 可以将光标跳转到 该行的括号上, 或者是在两个 ( ) 之间切换光标位置.
- da) 会删除本行的第一个括号间的内容.
- d% 会删除从光标的位置开始直到第一个括号结束之间的内容.
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)
整个标签和标签包围的文本
it
inner tag block (tag excluded)
被标签包围的文本
tag selection:
cursor need to be inside tag itself
da< 或 da>
删除这个tag
di< 或 di>
删除tag中的文本