Step 5 of 6

9. Operators Motions And Text Objects

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.

  1. Yank a sentence Put the cursor inside any sentence, then type yis.
  2. Delete inside a quoted string Move within one of the " strings and type di".
  3. Delete around a parenthesized group Move inside a ( ) pair, then type da( — the parentheses go too.
  4. Indent a paragraph From anywhere in a paragraph, type >ip.
Yank a sentence Put the cursor inside any sentence, then type yis.

Next: Delete inside a quoted string

Loading editor…