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

How do I visually select the text of a sentence without selecting surrounding whitespace?

Answer

vis

Explanation

The is (inner sentence) text object selects the sentence the cursor is in — excluding any leading or trailing whitespace that separates sentences. It is the inner counterpart to as (around sentence), which includes the surrounding whitespace.

How it works

  • v enters Visual mode
  • is selects the inner sentence: the sentence text itself, up to (but not including) the whitespace that follows the closing punctuation
  • A sentence ends at ., !, or ? followed by a space, tab, or end-of-line
  • vas (around sentence) includes the trailing whitespace — used when deleting a sentence cleanly without leaving extra spaces
  • Works in Normal mode too: dis deletes the inner sentence, cis changes it, yis yanks it

Example

Given this paragraph:

The quick brown fox jumps. A dog barked loudly. The end.

With the cursor on barked, pressing vis selects A dog barked loudly. (the sentence text, no trailing space). Pressing cis then lets you type a replacement sentence.

Tips

  • The is/as objects are most useful when editing prose, comments, or docstrings
  • Use ( and ) in Normal mode to jump between sentences before selecting
  • For programmatic text (where sentences are rare), prefer word (iw), paragraph (ip), or block (iB) objects
  • dip deletes an inner paragraph; dis and dip together let you clear text at two different granularities without losing your surrounding context

Next

How do I run a search and replace only within a visually selected region?