Vim’s various text objects
Now that we understand the distinction between inner and outer text objects, let’s explore what Vim provides us with.
Each of the text objects below has an inner and outer variant. If you read p, that means you can use ip for the inner variant and ap for the outer variant.
- w — used for selecting words
- W — used for selecting WORDS
- p — used for selecting paragraphs
- s — used for selecting sentences
- " — used for selecting text captured by the " character
- ' — used for selecting text captured by the ' character
- { — used for selecting text captured by curly braces — } and B (for block) also work
- ( — used for selecting text captured by parentheses — ) and b (for block) also work
- [ — used for selecting text within a pair of square brackets — ] also works
- < — used for selecting text captured by angle brackets — > also works
- t — used for selecting text captured by a HTML-/XML-style tag
There’s a lot of them! Thankfully, they are mostly intuitive — if you’re targeting a quoted string, you use ", or if you’re targeting the text within some parentheses, you use (.
Let’s practice. In the editor, you’ve got some text that is full of places where you can use these text objects. Work through the checklist below, combining them with the operators we learned earlier.