Step 4 of 6

9. Operators Motions And Text Objects

Text objects — inner versus outer

To edit efficiently in Vim, you must think beyond individual characters. Expert Vimmers think in terms of words, sentences, paragraphs, and blocks of code. In Vim, each of these higher-level constructs is called a text object.

Like operators, there are many text objects available in Vim, and you can even create your own.

“Inner” and “outer” text objects

The built-in text objects in Vim take two forms: inner and outer. Inner text objects begin with i, and outer text objects begin with a. The difference between them is subtle, but important.

Generally speaking, inner text objects capture the inner content of the given construct, whereas outer text objects capture both the inner content and the surrounding context.

To illustrate the difference, let’s think about the i" and a" text objects. These are useful when you want to operate on a quoted string. Which one you should use depends on what you’re trying to achieve.

There’s a quoted string in the editor. Work through the checklist below to see the difference for yourself. You’ll notice that vi" captures the content within the quoted string, and va" captures everything within the quotes including the quotes themselves (and any preceding whitespace).

  1. Select inside the quotes Place your cursor within the quoted string on the last line, then type vi".
  2. Select around the quotes Press Escape to drop the selection, stay within the quotes, then type va".
Select inside the quotes Place your cursor within the quoted string on the last line, then type vi".

Next: Select around the quotes

Loading editor…