Learn Vim / How to Edit Text Inside Quotes in Vim

How to Edit Text Inside Quotes in Vim

The answerPress ci" — change inside quotes. It finds the quotes on the line even if the cursor isn't between them yet.

Try it on a real buffer

With the cursor anywhere on line 1, press ci" to change everything inside the quotes, type exactly hello, world then Esc.

greeting = "wrong message"
print(greeting)

Canonical solution: ci" hello, world Esc · target: 16 keystrokes — the fewest that solve it (every keypress counts).

Why it works

ci" finds the quotes on the current line even if the cursor isn't inside them yet. The family is huge: i" / a" (inside / around quotes), i( , i{ , i[ , it for HTML tags…

Variations

KeysWhat it does
ci"change inside double quotes
ci'change inside single quotes
di"delete inside quotes
yi"copy inside quotes
ci( ci{ ci[same idea for brackets
▶ live vim buffertarget 16 keystrokes
With the cursor anywhere on line 1, press ci" to change everything inside the quotes, type exactly hello, world then Esc.

Reading about keystrokes doesn't build keystrokes. Try this in a real vim buffer right now — the “Fix the string” mission takes about a minute.

Sign in free to practice →

Keep going