Learn Practice Daily golf Reference

How to change text inside quotes or brackets in Vim

With the cursor anywhere inside the quotes, press ci" in Normal mode. The text between the quotes goes and you type the new text, then Esc. ci(, ci{ and cit do the same inside brackets and HTML tags.

The ninja lifting the old filling out of a pair of big glowing quote-mark bookends with tongs, the bookends staying in place, a ci" keycap on the counter.

Winter hours start on Monday, and the shop's website still says it's open until ten. The cursor is in the middle of the opening hours in the config file. You want everything between the quotes gone and the new hours typed in, without counting characters or hunting for the closing quote.

Before
hours: "11:00 to 22:00",
ci"11:00 to 20:00Esc
hours: "11:00 to 20:00",
From anywhere inside the string, ci" empties it and leaves you typing between the quotes. The quotes themselves stay
Try it here

Winter hours

The cursor is inside the opening hours.

Empty the string with ci", type 11:00 to 20:00, then press Escshop.js
3export const shop = {
2 name: "Byte Burrito",
1 greeting: "Hola! What can we wrap for you?",
4 hours: "11:00 to 22:00",
1};
NORMALLoading the editor…0.0sLn 4, Col :20
Open this text in the playground

This editor needs a keyboard. Read on, and play it at your computer.

Brackets and HTML tags work the same way

Read ci" as "change inside quotes". The last character names what to look inside, so ci( changes what's between parentheses, ci{ between braces, ci[ between square brackets and cit between an HTML tag and its closing tag. Single quotes and backticks work too, with ci' and ci`.

The cursor doesn't even have to be inside yet. If it's earlier on the line, Vim finds the next pair after it, so ci( at the start of price(order) changes order, and cit at the start of a line of HTML changes the text in that line's tag. The shop's specials list is a good place to try it.

Try it here

New specials

The specials change with the season. The cursor is at the start of the first item, before its tag.

Change the text in the tag with cit, type Mushroom, then Escmenu.html
1<ul class="specials">
2 <li>Carnitas</li>
1 <li>Al pastor</li>
2</ul>
NORMALLoading the editor…0.0sLn 2, Col :1
Open this text in the playground

This editor needs a keyboard. Read on, and play it at your computer.

Delete instead of change

Swap the c for d to delete without typing anything after. di" empties the string and leaves the quotes, which is what you want before pasting something in. da" reads as "delete a string" and takes the quotes too, along with the space after them. When pairs sit inside each other, Vim picks the innermost pair of the kind you asked for.

Check yourself

Quotes inside brackets

The cursor is on the t of winter, inside the quotes, which are inside the parentheses. In Normal mode you press ci( and then Esc. What does the line say now?

BeforeJust a picture: pick an answer below (1, 2, 3, 4)
1let x = price(order, "winter");
NORMAL
Pick an answer (click it, or press its number), then watch the engine play the keys to check it.
KeysChanges or deletes
ci" / ci' / ci`the text inside the quotes, then Insert mode
ca"the string, quotes included, then Insert mode
di"the text inside the quotes, leaving ""
da"the string, its quotes and the space after it
ci( or cibeverything between ( and )
ci{ or ciBeverything between { and }
ci[ / ci<everything between [ and ], or < and >
cit / datthe text inside an HTML tag / the whole element, tags included
vi" / yi"select / copy what's inside instead
ciwthe word under the cursor (a word works like a pair too)