sponsor Vim development Vim logo Vim Book Ad

basic Tip #5: Quickly searching for a word

 tip karma   Rating 877/307, Viewed by 24992 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

created:   February 24, 2001 17:57      complexity:   basic
author:   yega@cisco.com      as of Vim:   5.7


To search for a word under the cursor in the current file you
can use either the "*" or "#" keys.

The "*" key will search for the word from the current cursor
position to the end of the file. The "#" key will search for the
word from the current cursor position to the top of the file.

Note that the above two keys will search for the whole word and not
the partial word.  This is equivalent to using the <word> pattern
in the search commands (/ and ?).

To search for partial matches, you can use the "g*" and "g#" key
sequence.

You can also use the mouse to search for a word.  This will only
work in the GUI version of VIM (gvim) or a console version
of VIM in an xterm which accepts a mouse. Also, the 'mousemodel'
should be set to 'extend'.  Add the following line to your .vimrc:

set mousemodel=extend

To search for a word under the cursor from the current cursor
position to the end of the file, press the shift key and click
on the word using the left mouse button.  To search in the opposite
direction, press the shift key and click on the word using the
the right mouse button.

To get more help on these, use

:help *
:help #
:help g*
:help g#
:help <S-LeftMouse>
:help <S-RightMouse>

 rate this tip  Life Changing Helpful Unfulfilling 

<< Any word completion | Using the % key >>

Additional Notes

atheeban@yahoo.com, October 8, 2002 11:28
Very good tip!.
kubieziel@gmx.de, November 2, 2002 14:28
I'm quite happy to find that tip now. I'm start using vim. So it will save lot of time. :-)
scherkas@tx.technion.ac.il, December 8, 2002 8:22
By default on Windows version <S-RightMouse> works [as backwards search], but <S-LeftMouse> does not.
This is because mousemodel is set to "popup".  (somebody knows why?)

If you want to use this nice feature [<S-LeftMouse> as forward word search], add
this line to _vimrc file, which is located in VIM installation directory:

set mousemodel=extend

izzyb@ecn.ab.ca, April 18, 2004 9:58
To turn the highlighting off...

:noh
Matthew.Biggin@UBS.com, August 18, 2004 0:13
I've been using gvim for years and turning this feature on is going to be really useful. Nice one.
kosharsj@yahoo.com, February 9, 2005 19:37
This is VI!  Use of the word "mouse" should be illegal.

Darn repulicans.
foo@bar.org, August 22, 2006 4:43
No , its VI Mproved.
foo@bar.2, September 30, 2006 10:16
i thought it was Vi IMproved...
Anonymous, January 31, 2007 1:26
How do I highlight the entire lines that contain a particular string  
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
SourceForge.net Logo