How to replace text between quotes in vi

Nikola picture Nikola · Jul 24, 2012 · Viewed 41.5k times · Source

Say I have this line of code:

$query = "SELECT * FROM table";

Is there a command in vi/vim which can instantly delete everything between quotes and position the cursor between them so I can start typing?

Answer

Eugene Yarmash picture Eugene Yarmash · Jul 24, 2012

Use ci", which means: change what inside the double quotes.

You can also manipulate other text objects in a similar way, e.g.:

  • ci' - change inside the single quotes
  • ciw - change inside a word
  • ci( - change inside parentheses
  • dit - delete inside an HTML tag, etc.

More about different vim text objects here.