With the syntax highlighting in vim, I get the handy feature where the matching paren or bracket will be highlighted when I put the cursor over it. Is it possible to do the same thing for quotes?
5 Answers
While not eloquent, one workaround is to select everything inside of matching quotes. You can do this by using the command:
vi"
This will select everything in-between the quotes. However, you won't get proper results with nested quotes as it will match the first found ".

- 36,042
- 30
- 97
- 119
-
I'm a big fan of this, it seems to work also with other characters if you replace the " with what you want to be inside. I'm not sure I understand what's going on though, could someone explain that? v is select and i is insert, so where does this behavior come from? – Alex Li Jul 16 '20 at 20:56
-
@AlexLi :help +textobjects Text Objects in vim are cool. This is a good article on them https://blog.carbonfive.com/2011/10/17/vim-text-objects-the-definitive-guide/ – Wayne Walker Oct 03 '20 at 17:05
The problem with quotes is that they are symmetrical. It would be very hard to determine which quotes belong with each other.
For instance: "Which \"quotes\" go with each other in this statement?"
This has been discussed on the vim mailing lists a few times, as well as in the bug trackers of a few of the auto-delimiter type plugins. In every case that I've seen, it's been decided that this is better left as is.

- 39,631
- 8
- 69
- 76
-
2Vim's quote text-objects (http://vimdoc.sourceforge.net/htmldoc/motion.html#aquote) already have the smarts to deal with that. The problem is that `searchpairpos()`, which is what the MatchParen plugin uses to highlight parens, isn't able to find matching quotes. – jamessan Jun 21 '10 at 20:45
-
3Clearly the vim folks have figured this out well enough to highlight the quoted text properly, so I can't see why it would be any harder to highlight the quote itself when the cursor is over it. And, wouldn't brackets have the same issue? E.g. `{Which \{bracket\} matches the first bracket?}` – Jed Daniels Jun 21 '10 at 20:52
The solution is here: Stackoverflow in matchquote except it has the unfortunate limitation that only the current line is considered. matchit seems to comes close by allowing defining of multi-line matches of words such as if/endif but still no multi-line possibility that I can figure out to get matching for " and '.

- 644
- 9
- 14
VIM already highlights quoted text in a different color, so you can easily identify strings. Do you really need it to match quotes when the whole string is already highlighted?

- 131,333
- 52
- 229
- 284
-
3
-
Fair enough, but I was trying to get at: "Why would you want to match quotes when vim already highlights the whole string for you". Can you give us a use case? – Justin Ethier Jun 21 '10 at 20:59
-
2It would convenient to be able to use the % command on a quote. (jump to matching parenthesis) – Rhys van der Waerden Feb 16 '11 at 22:39
From :h matchparen
The characters to be matched come from the 'matchpairs' option. You can change the value to highlight different matches. Note that not everything is possible. For example, you can't highlight single or double quotes, because the start and end are equal.

- 147
- 1
- 3