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 wordsW— used for selecting WORDSp— used for selecting paragraphss— 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 —}andB(for block) also work(— used for selecting text captured by parentheses —)andb(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 workst— 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. Try using them in conjunction with the operators we learned earlier!