Search question/suggestion?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Search question/suggestion?

Eric Desjardins
Hi,

I do not know if it is possible or how to do it but it would be nice if
we could start another search in vim using a different highlight colour.

Eric


Reply | Threaded
Open this post in threaded view
|

Re: Search question/suggestion?

Mikołaj Machowski
Dnia pi?tek 19 sierpie? 2005 16:10, Eric Desjardins napisa?:
> Hi,
>
> I do not know if it is possible or how to do it but it would be nice if
> we could start another search in vim using a different highlight colour.
>
AFAIK there is script for this on http://www.vim.org

m.
--
        The world really isn't any worse.
        It's just that the news coverage is so much better.

Reply | Threaded
Open this post in threaded view
|

Re: Search question/suggestion?

Tim Chase-2
In reply to this post by Eric Desjardins
> I do not know if it is possible or how to do it but it would
> be nice if we could start another search in vim using a
> different highlight colour.

If I understand what you're asking, you want to highlight
successive matches with different colors.  An easy solution that
comes to mind is to make use of the two diff. coloring groups,
"Search" and "IncSearch".  Then, if you have both 'hls' and
'incsearch' set, it will highlight your last match in "Search"
colors, and your current (first) match in "IncSearch".

For more on that, see

        :help hl-search
        :he hl-incsearch
        :he hls
        :he incsearch

With a bit more chicanery, one might be able to have a rotating
list of colors, creating highlight groups on the fly based on the
contents of the @/ register.

This would likely involve an exec() call, after building a "syn
match" statement or a call to ":match".  If you only want the
most recent search (that is, two levels of searching), something
like this might work nicely in conjunction with having 'hls' set:

nnoremap / :exec(":match ErrorMsg /".escape(@/,'/')."/")<cr>/

where "ErrorMsg" is the highlight color-group you want your
previous match to be.  Groups you have available can be listed by
doing

        :hi

I'm not sure I've caught all the things that need to be escaped
there in the escape() call, but that's easy enough to modify.

Hope this helps,

-tim