How do I use a count with text objects to operate on multiple text objects at once?
Answer
d2iw
Explanation
Text objects in Vim accept a count, letting you operate on a span of multiple adjacent text objects in one command. For iw (inner word), Vim alternates between selecting the word and then the surrounding whitespace, so d2iw deletes the current word plus the whitespace that follows — not the next full word.
How it works
The pattern is {operator}{count}{text-object}:
{operator}—d(delete),c(change),y(yank), etc.{count}— how manyiwunits to include{text-object}—iw,aw,i(,a",ap, etc.
With iw, each successive unit alternates: word → whitespace → word → whitespace. So the count determines how far the region extends.
Example
Given the line (cursor on one):
one two three four
d2iw→two three four(word + following space =one)d4iw→three four(word + space + word + space =one two)d2aw→three four(2 "around word" objects each include trailing space)y2ap— yanks two paragraphs at once
Tips
- Use
d2aword4iwwhen you want to delete two complete words with their whitespace - Works with all text objects:
2i",2a(,2ap,2it— each has its own expansion semantics - Count goes between the operator and text object:
d3iw, not3diw(though both work in practice for most text objects)