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

How do I navigate and operate on sentences and paragraphs in Vim?

Answer

( / ) / { / }

Explanation

Vim treats sentences and paragraphs as first-class navigation units. The ( and ) commands move by sentences, while { and } move by paragraphs. These motions also work with operators for powerful text manipulation.

Sentence motions

  • ) moves to the beginning of the next sentence
  • ( moves to the beginning of the previous sentence
  • A sentence ends with ., !, or ? followed by whitespace or end of line

Paragraph motions

  • } moves to the next blank line (end of paragraph)
  • { moves to the previous blank line (start of paragraph)
  • Paragraphs are separated by blank lines

Text objects

" Sentence text objects
das    " Delete a sentence (including trailing space)
dis    " Delete inner sentence (no trailing space)
cas    " Change a sentence
vas    " Visual select a sentence

" Paragraph text objects
dap    " Delete a paragraph (including trailing blank line)
dip    " Delete inner paragraph (no trailing blank line)
cap    " Change a paragraph
vap    " Visual select a paragraph

Example: Reformat a paragraph

vipgq    " Select inner paragraph, then reformat to textwidth
gqap     " Same thing using operator + text object

Tips

  • } and { are among the fastest ways to move through code — blank lines separate logical blocks
  • In code, { and } jump between function boundaries, class definitions, and other blank-line-separated sections
  • dap is the fastest way to delete a function or block of code separated by blank lines
  • Combine with counts: 3} moves forward 3 paragraphs
  • For prose editing, sentence motions are essential; for code, paragraph motions are more useful

Next

How do I always access my last yanked text regardless of deletes?