> -----Original Message-----
> From: Suresh Govindachar [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, April 26, 2006 1:00 AM
> To: [email protected]
> Subject: Making * search for strings
>
>
> 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 have the following in my vimrc:
" Courtesy of Michael Naumann, Jürgen Krämer
" Visually select text, then search for it
if version >= 602
" Here are two enhanced versions of these mappings which use VIM 6.2's
" getregtype() function to determine whether the unnamed register
contains
" a characterwise, linewise or blockwise selection. After the search has
" been executed, the register *and* its type can then be restored with
" setreg().
vnoremap <silent> * :<C-U>
\let old_reg=getreg('"')<bar>
\let old_regmode=getregtype('"')<cr>
\gvy/<C-R><C-R>=substitute(substitute(
\escape(@", '\\/.*$^~[]' ), "\n$", "", ""),
\"\n", '\\_[[:return:]]', "g")<cr><cr>
\:call setreg('"', old_reg, old_regmode)<cr>
vnoremap <silent> # :<C-U>
\let old_reg=getreg('"')<bar>
\let old_regmode=getregtype('"')<cr>
\gvy?<C-R><C-R>=substitute(substitute(
\escape(@", '\\/.*$^~[]' ), "\n$", "", ""),
\"\n", '\\_[[:return:]]', "g")<cr><cr>
\:call setreg('"', old_reg, old_regmode)<cr>
endif
Basically, using visual mode, select whatever text you like and press * (or
# for reverse). These use the same keys as *,# in normal mode, so they are
very easy to remember. I use these maps all the time, very useful.
HTH,
Dave