Home » Questions » Computers [ Ask a new question ]

In vim, is there a way to search for a word in a different window?

In vim, is there a way to search for a word in a different window?

I'm working with a file where definitions, and references to those definitions are in different parts of the file. I'm looking at the file in a split window - one half looking at the definition, the other half looking at a reference, so that I can update both, and then easily move onto the next definition.

Asked by: Guest | Views: 279
Total answers/comments: 1
Guest [Entry]

"This page contains a snippet similar to what you're looking for. It takes the current word (as if you've pressed *), switches to the other window and searches for it with n:

:nnoremap <Leader>w :let @/=expand(""<cword>"")<Bar>wincmd w<Bar>normal n<CR>

You can change the <Leader>w part to any combination you like (even to something like *, thereby replacing its default functionality)."