0

Is it possible to have % motion work with matching quote " or '?

For example if we have text:

"Lorem ipsum is placeholder text (commonly used in the graphic),
'print, and publishing industries' for previewing layouts and visual mockups"

I would love to jump to matching ' or " when cursor is on one of them by pressing %. It works with all the brackets, i.e. ([{, but nothing happens when standing on a bracket.

:help 'matchpairs' states that its not possible to match same character pairs. Is there a workaround for this limitation, because vi" works just fine?

1
  • We have several similar questions on this site, but I couldn't easily find an exact duplicate or one that offered a solution. The problem of course is that, without context, " has no direction, so in general what you're asking for isn't possible. It's easy to knock up something with an expression mapping, but it gets a bit more complicated depending on precisely how you actually want it to work: it might be worth giving a few examples of how you'd want it to function on actual buffer contents (in particular, how you'd like it to handle edge cases).
    – Rich
    Sep 29 at 13:47

1 Answer 1

2

I turned the best workaround I could come up with into a plugin: vim-matchquote.

In a nutshell it figures out whether you are on an "odd" or "even" quotation mark character and jumps forward or back respectively.

The trickiness comes from integrating with the various versions of matchit that have been bundled with vim over the years.

2
  • Works like a charm :)
    – niekas
    Sep 29 at 14:13
  • That's great to hear! Sep 29 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.