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

How do I delete, change, or yank an entire sentence as a text object in Vim?

Answer

das

Explanation

Vim defines a sentence as text ending with ., !, or ? followed by whitespace or a newline. The as (around sentence) and is (inner sentence) text objects let you operate on complete sentences in one motion — no need to manually select from the start of a capital letter to the trailing period.

How it works

  • as selects the sentence and the trailing whitespace (or leading whitespace if at end of paragraph).
  • is selects the sentence text only, without surrounding whitespace.
  • Combine with any operator: d (delete), c (change), y (yank), v (visual select), gU (uppercase), etc.

Example

Given the text:

The quick brown fox. It jumps over the lazy dog. Then it runs away.

With the cursor anywhere on It jumps over the lazy dog.:

  • das → deletes the sentence including one space: The quick brown fox. Then it runs away.
  • dis → deletes only the sentence text, leaving the space: The quick brown fox. Then it runs away.
  • cas → deletes and enters insert mode to type a replacement sentence.

Tips

  • ( and ) navigate between sentence boundaries without selecting them.
  • Sentences must end with ., !, or ? followed by two spaces, a tab, or a newline for Vim to recognise them. A single space after a period (common in modern writing) may not be recognised — adjust with :set nrformats has no effect here; instead consider using a visual selection.
  • Works in visual mode too: vas to enter visual mode selecting the sentence.
  • Use 3das (or d3as) to delete three consecutive sentences at once.

Next

How do I run the same Ex command in every open tab page at once?