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
venters visual modeipis 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
dipto delete the inner paragraph without entering visual mode - Use
yipto yank (copy) the inner paragraph - Use
cipto change (replace) the entire paragraph - Use
=ipto auto-indent the current paragraph - Use
gqipto reformat (rewrap) the paragraph to the currenttextwidth - In code files, paragraphs often correspond to function bodies or logical blocks separated by blank lines, making
vipa fast way to select them