In vim, is there a plugin to use % to match the corresponding double quote (")?

Solution 1:

Depending on your reason for needing this, there may be a better way to accomplish what you're looking for. For example, if you have the following code:

foo(bar, "baz quux")
              ^

and your cursor happens to be at the ^, and you want to replace everything inside the quotes with something else, use ci". This uses the Vim "text objects" to change (c) everything inside (i) the quotes (") and puts you in insert mode like this:

foo(bar, "")
          ^

Then you can start typing the replacement text. There are many other text objects that are really useful for this kind of shortcut. Learn (and use) one new Vim command per week, and you'll be an expert in no time!

Solution 2:

Greg's answer was very useful but i also like the 'f' and 'F' commands that move the cursor forward and backward to the character you press after the command.

So press f" to move to the next " character and F" to move to the previous one.

Solution 3:

I have found this technique very useful for going to the start/end of a very long quoted string.

  1. when cursor is inside the string, visually select the whole string using vi" or vi'
  2. go to start/end of the string by pressing o
  3. press escape to exit visual select mode

this actually takes the cursor next to the start/end quote character, but still feels pretty helpful.

Edit

Adding Stefan's excellent comment here which is a better option for anyone who may miss the comment.

If you use va" (and va') then it will actually visually select the quotes itself as well.

– Stefan van den Akker