In your daily Vim adventures, you’ve likely befriended the stalwart
trio of c
, d
, and y
—the dependable
companions for changing, deleting, and yanking (copying). When paired with
f
or t
, they transform into text-seeking missiles,
zeroing in on your target character with unnerving precision.
For example:
dtX
deletes everything up to (but not including) the first X
. A clean cut, as if the rest of the line offended you.
cfX
changes everything up to and including the first X
, then whisks you away to insert mode, inviting you to write a better version of reality.
yfX
yanks everything up to and including the first X
, storing it neatly for future shenanigans.
But what if the first X
isn’t the one you’re after? Suppose you’re
chasing the third X
instead of the first. Sure, you could
count manually and use something like c3tX
. However, Vim offers an
alternative for those less inclined to count (or the chronically lazy):
patterns.
By wielding /pattern
after d
, c
, or
y
, you can aim at words, phrases, or even entire existential
crises:
d/fine leather jackets
deletes everything leading up to “fine leather jackets” (because probably, they weren’t that fine).
c/pirate
changes everything until “pirate,” leaving you to decide if it should say “mighty pirate” instead.
y/Chuck the Plant
yanks everything up to the illustrious plant.
This pattern magic lets you strike with surgical precision—perfect for those who know exactly what they want.
Did you know this already?
Rate this tip to help refine your daily lineup: 👎 / 👍 / 👌/ 🙌
No vote? We’ll assume you’ve got this one down!