How do I delete or change an entire paragraph of text in one motion?
Answer
dap / dip
Explanation
The dap and dip commands use Vim's paragraph text objects to delete an entire block of contiguous text in a single motion. A paragraph in Vim is defined as a block of non-empty lines separated by blank lines — making these commands perfect for deleting functions, configuration blocks, log entries, or prose paragraphs without counting lines.
How it works
dis the delete operatoripis the "inner paragraph" text object — it selects all contiguous non-blank lines around the cursorapis "a paragraph" — it selects the paragraph plus the trailing blank line (or leading blank line if at the end of the file)- The cursor can be anywhere within the paragraph — Vim finds the boundaries automatically
Example
Given the text with the cursor anywhere on beta or gamma:
alpha
beta
gamma
delta
epsilon
Pressing dap deletes the middle paragraph and its trailing blank line:
alpha
epsilon
Pressing dip instead would delete only the three lines, leaving the surrounding blank lines intact:
alpha
epsilon
Tips
- Use
capto delete the paragraph and enter insert mode, ready to type a replacement - Use
yapto yank (copy) a paragraph for pasting elsewhere - Use
vapto visually select the paragraph first so you can verify the boundaries before acting dapis cleaner thandipwhen rearranging blocks because it removes the trailing whitespace, preventing double blank lines- Combine with
.to repeat:dapon one paragraph, move to another, press.to delete that one too - The
{and}motions move backward and forward by paragraph — use them to navigate between blocks quickly before operating - Paragraph text objects work beautifully with other operators:
=apre-indents a paragraph,gqapreformats it to fittextwidth,>apindents it by one shiftwidth - In code, paragraphs correspond to blocks separated by blank lines, which often aligns naturally with functions, classes, or logical sections