โŒจ๏ธ vim/ ยท 05_text_objects.md

Chapter 5: Text Objects

๐Ÿ“„ vim/05_text_objects.md

Chapter 5: Text Objects

In the previous chapter, Operator Execution, we learned how to combine an Operator (like Delete) with a Motion (like "move to next word").

This works great if you are at the start of the word. But what if you are in the middle?

The Problem: Dumb Ranges vs. Smart Objects

Imagine you have this code, and your cursor is on the letter r in "Error":

console.log("Error Message");
              ^ Cursor is here

If you type dw (Delete Word), Vim calculates the range from the cursor (r) to the next word start (M). Result: console.log("E Message");

This is rarely what you want. You usually want to delete the whole string "Error Message".

The Solution: The "Magic Wand"

Standard Motions (w, j, $) are like drawing a line with a ruler. They go from Point A to Point B.

Text Objects are like the "Magic Wand" tool in Photoshop. You click inside an object, and the software automatically figures out the boundaries based on context.

Instead of saying "Delete from here to the end," you say:

Key Concepts

To implement this, we stop thinking about "movement" and start thinking about "boundaries."

1. Inner (i) vs. Around (a)

Every text object comes in two flavors. Think of a text object like an orange.

Example: ( hello )

Next Chapter: Operator Context


Generated by Code IQ