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?
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!