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

How do I select an entire paragraph in Vim?

Answer

vip

Explanation

The vip command visually selects the inner paragraph — all contiguous non-blank lines surrounding the cursor. It is one of the most useful text object selections for quickly grabbing a block of text or code.

How it works

  • v enters visual mode
  • ip is the "inner paragraph" text object — it selects all consecutive non-blank lines around the cursor, excluding any surrounding blank lines

A "paragraph" in Vim is defined as a block of text separated by one or more empty lines.

Example

Given the text with the cursor anywhere on the second paragraph:

First paragraph line one.
First paragraph line two.

Second paragraph line one.
Second paragraph line two.
Second paragraph line three.

Third paragraph.

Pressing vip selects:

Second paragraph line one.
Second paragraph line two.
Second paragraph line three.

Only the three lines of the second paragraph are selected, without the surrounding blank lines.

Tips

  • Use vap ("a paragraph") to select the paragraph plus one trailing blank line — useful for moving or deleting a paragraph cleanly
  • Use dip to delete the inner paragraph without entering visual mode
  • Use yip to yank (copy) the inner paragraph
  • Use cip to change (replace) the entire paragraph
  • Use =ip to auto-indent the current paragraph
  • Use gqip to reformat (rewrap) the paragraph to the current textwidth
  • In code files, paragraphs often correspond to function bodies or logical blocks separated by blank lines, making vip a fast way to select them

Next

How do I edit multiple lines at once using multiple cursors in Vim?