CodeRigor

FREE LESSON

Vim text objects: iw aw, i( a(, i" a"

Edit whole words, bracket contents and strings from anywhere inside them.

After an operator (d, c, y), you can name a text object instead of a motion. It works from anywhere inside the object:

Object Inner (i…) Around (a…)
w / W the word word + trailing space
( or b inside the parentheses including the parentheses
{ or B inside braces including braces
[ < inside brackets / angle brackets including them
" ' inside the string including the quotes
Text
ciw    change the word under the cursor
ci(    replace a whole argument list
ci"    rewrite a string literal
daw    delete a word without leaving a double space
ci( vs ca( on draw(x, y, z);
With the cursor anywhere inside the parentheses, i( covers just the arguments and a( includes the parentheses: ci( then types the new argument list.
ci( vs ca( on draw(x, y, z);
With the cursor anywhere inside the parentheses, i( covers just the arguments and a( includes the parentheses: ci( then types the new argument list.

Rule of thumb: i for "replace the contents", a for "remove the thing".

Watch & read

Free lectures, talks and readings that cover this skill from another angle. All resources →

Text objects as nouns (iw, i(, a") and why they compose with every operator.