Search code examples
selectsearchvimhighlightmode

VIM: how to highlight selected words from another buffer's visual mode?


I've file1 and open in vim like this:

Hello us
Hello us uk
Hello us us uk uk
Hello us us us uk uk uk

I locate on 4th statement and use veeey to select 3 words(us uk uk)

Then I use 'e' command to open another buffer, say file2, so how to search and highlight the selected words from file1? I don't wish to type again each time.

Thanks.


Solution

  • After selecting, y to yank. Then later in the new buffer, / to start the search, Ctrl+R" to paste from the default register, CR to start the search.

    If you want to reuse your copied snippet, you may want to stuff it into a named register (as the default register gets overwritten all the time): "ay to yank into the register "a" (or whatever other register), then later /Ctrl+RaCR to search.

    :help registers
    :help c_CTRL-R