# Find based on text objects

I am a big fan of text objects, and I like their composability. For example, if I have

\label{sec:this-is-a-section}


I can easily copy the sec:this-is-a-section part by navigating inside, and pressing yi} and use this, for example, to paste it after a \ref{ somewhere else.

What I am missing is a good way to jump between these two. Intuitively, I want a command that takes a text object (i}) selects this and searches for it. Does that exist, or is there a succinct way to achieve this?

There is such a thing for the specific case of the iw text object, namely the * command. So in a way I wonder if there is a generalization of this.

I am not looking for ways to jump between \label and \ref, e.g. with a tag file; these are just example for the purpose of the question.

• How about pasting on the commandline? I.e. yank your object (yi}), and then press /<Ctrl-r>=<Enter> to search for it. – PhilippFrank Oct 28 '15 at 10:12
• From reading stackoverflow.com/a/3997110/946226 I would expect "/yi} to do something along these lines, but unfortunately, it cannot be used with y and p, although I wonder why. – Joachim Breitner Oct 28 '15 at 12:20
• @PhilippFrank, it seems your suggestion is the best (if one wants a solution that works without scripting/plugins); would you mind turning it into an answer? – Joachim Breitner Oct 28 '15 at 19:53
• Not at all. I'll also fix the register name :) – PhilippFrank Oct 29 '15 at 11:31

Pasting in commandline-mode from a register is done via <C-r>(see :h <C-r>, this also works in insert mode). So you could simply yank your text object, be it via yi} or visual selection, and then type /<C-r>"<Enter> to search for it.
• True. You might get quite a long way by using \V (:h \V, the very-nomagic switch) before pressing <C-r> though. – PhilippFrank Oct 29 '15 at 13:55
The visual-star-search plugin can be used to search for a visual block. It solves your problem: select an object the usual way, then press *.
• @JoachimBreitner Then you're missing the useful implementations of objects. But visual-star-search has 17 lines, you can copy the relevant parts to your config. – Sato Katsura Oct 28 '15 at 15:13