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?
The first method to print the double quotes with the string uses an escape sequence, which is a backslash ( \ ) with a character. It is sometimes also called an escape character.
Firstly, double quote character is nothing special in regex - it's just another character, so it doesn't need escaping from the perspective of regex. However, because Java uses double quotes to delimit String constants, if you want to create a string in Java with a double quote in it, you must escape them.
press q and q for recording into q register (we use "q" as shortcut to remember "quotes"). press a then press ' again to surround the word with quotes.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With