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


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.

  • 1
    How about pasting on the commandline? I.e. yank your object (yi}), and then press /<Ctrl-r>=<Enter> to search for it. 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. 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? Oct 28 '15 at 19:53
  • Not at all. I'll also fix the register name :) 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.

  • Quite nice, although it probably breaks down if the selected text contains special regex characters. Oct 29 '15 at 13:20
  • True. You might get quite a long way by using \V (:h \V, the very-nomagic switch) before pressing <C-r> though. 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 *.

  • I am reluctant to install plugins, but it is a good start. Oct 28 '15 at 12:12
  • @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. Oct 28 '15 at 15:13
  • Copying to the config is even worse. I, as far as possible, try to make use of plain vim in order to be able to use other computers without hassle. But that’s getting OT :-) Oct 28 '15 at 19:12
  • Then re-type the commands to the config. The plugin consist of ~5 "plain Vim" commands. It isn't like there are 216 other ways of doing it, you know. :) Also, the advantage of installing the ~5 commands via a plugin is that somebody else is taking care of collecting bug reports, and fixing bugs. Oct 28 '15 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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