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

How do I quickly change the text between any pair of delimiters?

Answer

ci" / ci( / ci{ / ci[ / ci` / ci'

Explanation

The ci{delimiter} family of commands changes the text inside any matching pair of delimiters. The cursor doesn't need to be on the delimiter — Vim finds the nearest enclosing pair and changes everything between them.

Available delimiter text objects

Command Target
ci" Inside double quotes
ci' Inside single quotes
ci`` Inside backticks
ci( or ci) Inside parentheses
ci{ or ci} Inside curly braces
ci[ or ci] Inside square brackets
ci< or ci> Inside angle brackets
cit Inside HTML/XML tags

Inner vs Around

  • ci" changes text inside quotes (preserves the quotes)
  • ca" changes text around quotes (deletes the quotes too)

Example

Given print("hello world") with cursor anywhere inside the quotes:

  • ci" → deletes hello world, leaves print(""), enters insert mode between quotes
  • ca" → deletes "hello world", leaves print(), enters insert mode

Works with all operators

di(    " Delete inside parentheses
yi{    " Yank inside curly braces  
vi[    " Visual select inside brackets
>i{    " Indent inside braces
gUi"   " Uppercase inside quotes

Tips

  • For quotes (", ', `), Vim searches forward on the current line if the cursor isn't already inside a pair
  • For brackets, Vim searches outward from the cursor to find the nearest enclosing pair
  • Combine with . (dot command): ci" on one string, then move to another and press . to repeat
  • This is widely considered the single most productivity-boosting feature of Vim's text objects

Next

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