vimtricks.wiki Concise Vim tricks, one at a time.

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 mode
  • 2 — count: apply the following text object twice
  • a — "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 i for inner: v2ip selects 2 inner paragraphs without surrounding blank lines
  • Combine with operators directly, skipping visual mode: d3ap deletes 3 paragraphs, gU2aw uppercases 2 words
  • Count text objects are especially useful for restructuring prose — select N paragraphs to move or reformat them at once

Next

How do I encode and decode JSON data in Vimscript for configuration and plugin development?