Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

What I want to be able to do, is find a word in one pane, and then search for that word in the other pane. Much like putting the cursor over a word in command mode, and pressing *, except that the current pane shouldn't move - the other should.

Is there a way to do this in vim?

Or, can anyone suggest a different way of working that would make this easier?

share|improve this question
up vote 2 down vote accepted

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).

share|improve this answer

I've found Vim's tabs to be more convenient than split windows. These tabs are available in the console version as well as the GUI. You may need more than a minimal build of Vim for the feature (in particular, the "+windows" compile option needs to be enabled).

Use :tabnew or :tabnew <file> to open a new tab. Use :tabnext (shortcut: gt) or :tabprev (shortcut: gT) to move to the next/previous tab. Use :close to close the current tab window.

See :help tabpage.txt for a basic reference.

As to the question of how to execute a search command in the former tab and have the latter move, I'm not sure -- Leader_Fire's answer may work, but might need tweaking.

share|improve this answer
Yeah yeah, tabs are great. I use them all the time when editing multiple files. In this case I want to view two parts of a file side by side, doing this in different tabs would defeat the purpose - I might as well search with *, and jump back with '' – SpoonMeiser Dec 9 '09 at 21:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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