How do I select, delete, or change a complete sentence using Vim's sentence text objects?
Answer
as and is
Explanation
Vim defines sentence text objects — as (around sentence) and is (inner sentence) — that allow any operator to act on an entire sentence in one motion. These text objects complement the more commonly known word and paragraph objects and are particularly useful when editing prose, documentation, or comment blocks.
How it works
isselects the inner sentence: the sentence text itself, without leading or trailing whitespaceasselects the around sentence: the sentence text plus any trailing whitespace that separates it from the next sentence- A sentence boundary is defined as a
.,!, or?followed by whitespace or the end of the line (configurable via:help sentence) - These objects combine with any operator:
d,c,y,g~,gU,gu,>, etc.
Example
Given the text (cursor anywhere on the second sentence):
This is the first sentence. It contains a bug. This is fine.
dis— deletesIt contains a bug.(leaves surrounding spaces)das— deletesIt contains a bug.(includes the trailing space)cis— changes the inner sentence, leaving you in insert mode to retypeyis— yanks the sentence without the surrounding whitespace
Tips
- Use
iswhen you want to retype a sentence from scratch (cis), sinceaswould also delete the space before the next sentence - Combine with counts:
d2asdeletes two sentences at once - Works across wrapped lines — a sentence can span multiple lines
- If your text doesn't use standard sentence endings, consider using paragraph text objects (
ip/ap) instead - Use
(and)to jump between sentences without text objects