I use the extreme version:

vnoremap <silent> * "yy:let @/='\(' . substitute( escape( @y,
'$*^[]~\/.' ), '\_s\+', '\\_s\\+', 'g' ) . '\)'<cr>:set hls<cr>

This escapes a lot of stuff, including replacing any whitespace with a
generic expression that includes newlines.  I like it because if you
highlight 'a b' (without the quotes) and hit *, it will subsequently
also match 'a             b', 'a\nb' (where the \n indicates that the a
and b are on different lines).  I got the idea from a previous
discussion on this list (might well have been Gerald posting his
mappings earlier).

Oh, and I also wrap the search string in \(\) to allow its use in later
search/replace expressions.  Lastly, I don't perform an actual search,
but rather set the search register and turn on highlights.  Why?  I like
to see all my matches, but I don't really want the cursor to move when I
hit *.

Clobbers the y register, but you can easily change the first two
characters of the mapping to do something else...

In a similar vein, by the way, if you want to search for something
currently on the clipboard, try:

noremap // :let @/[EMAIL PROTECTED]<cr>:set hls<cr>

Regards,

Salman. 

> -----Original Message-----
> From: Gerald Lai [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, April 26, 2006 1:30 AM
> To: Suresh Govindachar
> Cc: [email protected]
> Subject: Re: Making * search for strings
> 
> On Tue, 25 Apr 2006, Suresh Govindachar wrote:
> 
> >
> > Hello,
> >
> >  By default, * searches for words:  /\<stuff_below_cursor\>  but I 
> > would like it to search for strings:  /stuff_below_cursor  
> One way is 
> > to use the following
> >
> >        map * yiw:let @/[EMAIL PROTECTED]<cr>
> >
> >  Is there a better way? ("/yiw didn't work.)
> 
> I found this somewhere in Vim tips:
> 
> "visual search
> vnoremap *           
> y/\V<C-r>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>
> vnoremap <kMultiply> 
> y/\V<C-r>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>
> vnoremap #           
> y?\V<C-r>=substitute(escape(@@,"?\\"),"\n","\\\\n","ge")<CR><CR>
> 
> HTH :)
> --
> Gerald
> 

Reply via email to