How do I find text with yanked text on vim?

Vim

Vim Problem Overview


Let us say that I yanked the following word: Cheese. Now I want to find Cheese within a text document. I hit the forward slash key(/)... and this is where I end. Is there a way to search with Yanked word? Also, is there a way you can use yanked words in substitution(s:/yanked/beef/g)?

Vim Solutions


Solution 1 - Vim

The most recently yanked text will be stored in the 0 and " registers (if no register was explicitly specified e.g. by "xy).

Then you can paste the text of any that register in the last line (either in search mode / or in last line command mode : ) with Ctrl-RX, where X is the register you want to paste.

For example:

/Ctrl-R0

Will paste the contents of the register 0 in the forward search command pattern.

Solution 2 - Vim

  1. yank the text
  2. press q/pEnter

q/: open the search history

pEnter: paste the yanked text on the command line and search

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRoyalPie717View Question on Stackoverflow
Solution 1 - VimChristian C. SalvadóView Answer on Stackoverflow
Solution 2 - Vimklchow916View Answer on Stackoverflow