How do I visually select multiple paragraphs or text objects at once using a count prefix?
Answer
v2ap
Explanation
In Vim, text objects accept a count prefix in visual mode, letting you select multiple consecutive text objects in one keystroke. Typing v2ap enters visual mode and immediately selects 2 paragraphs around the cursor. This works with any text object and is faster than making an initial selection and then extending it.
How it works
v— enter characterwise visual mode2— count: apply the following text object twicea— "around" modifier (includes surrounding whitespace/delimiters)p— paragraph text object
The count multiplies how many consecutive text objects are selected, anchored at the cursor's current position.
Example
Given a file with three paragraphs separated by blank lines, with the cursor in paragraph 1:
First paragraph here.
It has two lines.
Second paragraph here.
Third paragraph here.
Pressing v2ap selects both the first and second paragraphs (including the blank line between them).
Pressing y2ap (without entering visual first) yanks 2 paragraphs directly.
Tips
- Works with all text objects:
v3aw(3 words around),v2as(2 sentences around),v2a{(2 brace blocks) - Use
ifor inner:v2ipselects 2 inner paragraphs without surrounding blank lines - Combine with operators directly, skipping visual mode:
d3apdeletes 3 paragraphs,gU2awuppercases 2 words - Count text objects are especially useful for restructuring prose — select N paragraphs to move or reformat them at once