Vim knows about text objects. A text object is a
part of text, such as word, sentence, block (block of text between
brackets), or paragraph. You define them by pressing
w
, s
, b
, or
p
. Vim knows about one text object related
specifically to markup languages - a tag. A tag corresponds to a pair
HTML/XML element.
Vim distinguishes between the inner part of a tag, and the whole tag including the surrounding markup. Vim can also select a text enclosed in quotes, or jump the cursor between left or right sharp brackets. Get inspired by the following few useful examples:
command | how to remember | description |
---|---|---|
it | inner tag | text placed inside XML element |
at | all tag | same as it + the pair of surrounding tags |
2it | 2 x inner tag | select the inner text of the parent element (including the current tag) |
2at | 2 x all tag | select the whole parent element (including the current and the parent tags) |
f> | find > | selects the text to the end of the closing tag, including '>' |
t< | find to > | selects the text to the end of the closing tag, without '<' |
F< | find < backward | selects the text from the beginning of the tag, including '<' |
T< | find to < backward | selects the text from the beginning of the tag, without '<' |
a" | a string | selects the text including the surrounding quotes, such as XML attribute |
i" | a string | selects the text without the surrounding quotes, such as text of an XML attribute |