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

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

  • d is the delete operator
  • ip is the "inner paragraph" text object — it selects all contiguous non-blank lines around the cursor
  • ap is "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 cap to delete the paragraph and enter insert mode, ready to type a replacement
  • Use yap to yank (copy) a paragraph for pasting elsewhere
  • Use vap to visually select the paragraph first so you can verify the boundaries before acting
  • dap is cleaner than dip when rearranging blocks because it removes the trailing whitespace, preventing double blank lines
  • Combine with . to repeat: dap on 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: =ap re-indents a paragraph, gqap reformats it to fit textwidth, >ap indents it by one shiftwidth
  • In code, paragraphs correspond to blocks separated by blank lines, which often aligns naturally with functions, classes, or logical sections

Next

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