Tuesday, January 25, 2011

Re: Highlight Search Results in Scratch Buffer from "Gather" function

Hi Roy!

On Di, 25 Jan 2011, Roy Fulbright wrote:

>
> I recently installed the "Gather" function described in Vim Tip 1557
> at http://vim.wikia.com/wiki/Filter_buffer_on_a_search_result. The
> function works great, but I would like to apply the original search
> criteria to the lines in the scratch buffer (with hlsearch on) to
> highlight the strings found.

> I tried /a:pattern after the results were appended to the scratch
> buffer, but that didn't work. How can I do this?

Without having read the article at the wiki, that doesn't work, because
you want to evaluate an expression. Therefore you'd need to use :exe.
This should work:
:exe ":norm! /" . a:pattern . "\<CR>"

But personally, I would use:
:call matchadd("Search", a:pattern).

This doesn't clutter your search register and the highlighting is
permanent. Use the functions clearmatches() and matchdelete() to delete
the highlighting. See the help add:

:h matchadd()
:h clearmatches()
:h matchdelete()
:h exe

> Thanks, Roy Fulbright

You are welcome.

Christian

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: