Frequently Asked Question

What are Vim text objects and why are they so useful?

A text object is a named region of structured text, "a word", "inside parentheses", "a paragraph", "around a sentence". You combine an operator (d delete, c change, y yank, v visual select) with i (inner) or a (around) and an object letter. So diw deletes the word the cursor is on, ci( changes whatever is inside the enclosing parentheses, yi" yanks the content of a string literal, dap deletes an entire paragraph including its trailing blank line.

The reason text objects feel transformative is that they describe intent rather than position. To delete the contents of a parenthesised expression without text objects, you would have to position the cursor exactly after the opening paren, count characters, and delete that range. With ci( you can be anywhere inside the parens, even on the parens themselves, and the editor figures out the boundaries. This works the same for [, {, <, single quotes, double quotes, backticks, and HTML/XML tags (it, at).

Plugins extend the idea further. vim-textobj-user lets people define custom objects: "inside a Python function", "around a method argument", "inside a Markdown code fence". vim-surround (Tim Pope) adds operators to add, remove, and change the brackets or quotes around an existing object ds" deletes surrounding double quotes, cs'" changes single quotes to double, ysiw] wraps a word in square brackets. The composition is what makes experienced Vim users feel they are editing at the speed of thought.

Further reading and video