History Report a problem
Article Edit this page Discussion

Search for current word in new window

From Vim Tips Wiki

Jump to: navigation, search
 

Tip 798Previous TipNext Tip

Created: October 1, 2004 Complexity: basic Author: Dave Silvia Minimum version: 6.0 Karma: 5/5 Imported from: Tip#798


You might want to search for the current word in another window, without changing the view shown by the current window. Enter the following then press \w (assuming the default backslash leader key). That will split the window, then search for the current word in the other window. Press n for the next match, or N for the previous match. When finished, press Ctrl-w c to close the window.

:nnoremap <Leader>w :let @/=expand("<cword>")<Bar>split<Bar>normal n<CR>
:nnoremap <Leader>W :let @/='\<'.expand("<cword>").'\>'<Bar>split<Bar>normal n<CR>

If the cursor is on "rain", pressing \w will find "rain" and "drain" and "rainbow". However, pressing \W will find "rain" only.

Alternatively, if you are already showing two windows on the same file (that is, you have used :split), then the following map will search for the current word in the other window. Press Ctrl-w w to return to the original window.

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

You can also use marks to return to where you started the search:

``   Returns to where you started the last search.
`.   Returns to where you last made an edit.

Or just set a mark (press mm), do the search, then return to the mark by pressing `m

[edit] References

[edit] Comments

 

Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Search for current word in new window"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation