All occurrences of text between quotes (like * but for the whole text, not a single word)

StackOverflow https://stackoverflow.com/questions/22144834

  •  19-10-2022
  •  | 
  •  

Question

When I edit XML-files I sometimes want to jump to the next occurrence of text between quotes. For example, when my cursor is on my.attr in attr="my.attr" I want to jump to the next occurence of my.attr. I want to do it via some key combination (like Shift + * which is for words occurrences). Is is possible?

No correct solution

OTHER TIPS

You can create a visual selection of the attribute value inside double quotes with vi". Then, there are several plugins that implement the * command for visual mode (usually by overloading the * command), i.e. they search for the next occurrence of the selected text. One such plugin is my SearchHighlighting plugin. (The plugin page has links to alternative plugins.)

Related plugins

If you want to change all attribute values (without constructing a :%s/ substitution), my ChangeGlobally plugin provides a gc{motion} and {Visual}gc command that does that.

I would yank the text inside the quotes with yi" (only works if the opening and closing quotes are on the same line) and then /<C-R>". (The <C-R> means CTRL-R, not 5 characters.)

This gives you a chance to modify the pattern before submitting it; as @Kalanidhi pointed out, you may have to escape some special characters. It uses the same i" text object as in @Ingo Karkat's answer.

If your text is short, then you can edit the command line with the arrow keys, but if it is long you may want to edit it in a command-line window with <C-F>. (Alternatively, if you are thinking ahead, use q/ instead of /.)

:help y
:help text-objects
:help c_CTRL-R
:help cmdline-editing
:help cmdline-window

You can use in command mode type /<exact pattern> if any special character then escape the special character like \

For example In command mode /"my\.attr"

So only search the exact pattern. N or n to move forward and backward .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top