6

Assuming the following situation

$someVar = "Some String with \"escaped\" inner delimiters";

with the cursor somewhere in the double-quote delimited string.

What is the quickest way to jump to the final (actually delimiting) double quote? I can only think of 3f"/f" depending on where the cursor is, or even using a negative lookbehind with /, but there has to be a better way?

Is there perhaps even something like "jump to the end of the current syntax-highlighted block"?

3 Answers 3

7

@Kent's solution assumes a single string in the line. Another approach is (mis-)using the a / inner quoted string text object (a" / i"), through visual mode:

  • va"<Esc> for :set selection=inclusive (default)
  • vi"<Esc> for :set selection=exclusive

@Kent's solution also doesn't work as a single, atomic {motion}, so you cannot use it after commands like d or y. That can be done via the vim ninja feet plugin as d]i".

2
$F"

This goes to the end of the line, and searches backwards for ".

0

You can use Search and Visual mode.

For nested quotes: Given your original string:

$someVar = "Some String with \"escaped\" inner delimiters";

From Normal mode, go to the start of the string; to do that you could run a search.

/"Enter

When you are there, go to Visual mode and search for the next instance.

vn

Now you must continue expanding the selection by running the next search instance multiple times to arrive at the end of the string (twice in the given example).

nn

And then you can copy or whatever you want as you have the content of the string selected.


Additionally, this solution can also be applied for multiline, let's say you have this block in your editor:

cons multiline = `this is
  a multiline
  string`;

This time run the search against the backtick "`"

/`Enter

When you are there, go to Visual mode and search for the next instance to arrive (end of the string)

vn

And again you have the string selected.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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