On Wed, 26 Apr 2006, Halim, Salman wrote:

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

Good idea :) I'll adopt it for my <kMultiply>. Question, do you think it
would be useful to extend this to numbers too? For example, visual
matching "123" results in "\d\+"?

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 *.
[snip]

The only reason I use

  let @/="<search>"<CR>

in mappings is not to polute the search history. If you don't want the
cursor to move when * is hit, you can do:

  nnoremap * *<C-o>
  nnoremap # #<C-o>

HTH :)
--
Gerald

Reply via email to