Jean-Rene David wrote:
* Robert Cussons [2006.10.18 09:29]:

Everything seems to work fine now, except the
searched for items aren't highlighted like they
normally are when I search


Whether or not search items are highlighted
depends on the value of the 'hlsearch' option.

The search item gets highlighted on my end when the
option is set. Is yours set?

:set hls?


This is quite strange, it is set, i.e.

:set hls?

returns

hlsearch

If I use your visual selection when I first launch gvim, then it works with the highlighting. If I then use <Enter> to clear the highlighting according to this line in my .vimrc that I gave before:

:nnoremap <CR> mz:nohlsearch<CR>/<BS><CR>`z

then the highlighting is no longer displayed as is expected.
If I then do

:set hls?

again, I get again:

hlsearch

but if I use your visual selection tool again then this time I get no highlighting. Of course if I set hls again using :set hls then it works fine again until I press enter.

So what I was thinking was just to add a :set hls at the start of your function, then it should alway highlight the searched for items, however I tried variations on including it but no nothing about scripting so they didn't work, can you tell me how I should add it? I tried the below but it didn't work.

Thanks,
Rob.

" Search for visually selected text {{{
" From an idea by Michael Naumann, Jürgen Krämer.
function! VisualSearch(direction) range
        set hlsearch
   let l:saved_reg = @"
   execute "normal! vgvy"
   let l:pattern = escape(@", '\\/.*$^~[]')
   let l:pattern = substitute(l:pattern, "\n$", "", "")
   if a:direction == 'b'
      execute "normal ?" . l:pattern . "\r"
   else
      execute "normal /" . l:pattern . "\r"
   endif
   let @/ = l:pattern
   let @" = l:saved_reg
endfunction

vnoremap <silent> * :call VisualSearch('f')<CR>
vnoremap <silent> # :call VisualSearch('b')<CR>


Reply via email to