Vim course Lesson 2 of 6

Vim from zero: a text object is the thing you act on

A text object names a span of text. i" is the inside of the double quotes. di" on item latte = "oat" deletes oat and leaves the quotes.

Zoe is one of GoByte's characters. This post was drafted by AI agents in Zoe's voice, then fact checked, run and edited by the GoByte team.

Back to top

A motion such as w moves the cursor. A text object names a span: this word, the inside of these quotes, the inside of these parentheses. An operator then acts on that span. d deletes. i" means inside the double quotes. Together, di" deletes the note the quotes hold and leaves the quotes, so you can type a different milk.

A text object names a span#

An operator needs a span. A text object names one without a count. i" means the characters inside the nearest double quotes, not the quotes themselves. d deletes that span. Starting from item latte = "oat", di" removes oat and leaves item latte = "". a" would include the quote characters. iw is the inner word, so diw on latte deletes the drink. c is the operator that deletes and then enters insert mode. The object stays the same. The verb changes.

di double-quote clears the note and keeps the qu
  1. beforetextitem latte = "oat"
  2. after di"textitem latte = ""
di"
item latte = ""

The cursor can sit on the quoted text#

Start with the line item latte = "oat" and the cursor anywhere between the quotes, or on either quote. di" deletes oat. The quotes stay, so the line reads item latte = "". i" is the object: inside, double quote. a" would include the quotes themselves, and the line would lose them too.

iw is the object for a word. diw with the cursor on latte deletes the drink and leaves the spaces around it to be cleaned up by the operator. You do not have to land on the first character and then count. The object finds the edges.

Operators and objects combine#

c changes: it deletes the span and leaves you in insert mode. ci" on the same line deletes oat and waits for you to type the replacement, which is how you change the milk without retyping the drink. y yanks, which is a copy. yi" puts oat in the default register and leaves the line alone. The object is the same. The operator is the verb. The next lesson is that verb plus a motion, which is the other way to name a span.

Report a mistake

Your product here? Partner with us

Back to top

Discussion

No comments yet. Signed in GoByte members with a verified e-mail can join. Community guidelines

Reading is open to everyone. Commenting and voting need a GoByte account with a verified e-mail.