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

Viewed 14465

The % key is one of the best features of vim: it lets you jump from { to }, [ to ], and so on.

However, it does not work by default with quotes: Either " or ', probably because the opening and closing quote are the same character, making implementation more difficult.

Thinking a bit more about the problem, I'm convinced that it should be implemented, by counting if the number of preceding quotes is odd or even and jumping to the previous or next quote, accordingly.

Before I try to implement it myself, I'd just like to know if someone already has?

5 Answers

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

Related