Wednesday, July 25, 2012

highlight found pattern within a function?

I created a function that given a string will modify it to make a
search pattern.

fu! Find(str)
" build search pattern based on str
let @/ = pattern
try
execute "normal /" . pattern . "\<cr>"
catch
endtry
endf

It works very well.

When I use the 'normal' find, I have it set to highlight all found.

When I use the function the pattern is found but not highlighted. If
':set hls' is added IN the function the found text is still NOT
highlighted. When 'n' is used to find the next occurrence... THEN the
text is highlighted.

I can use a command like this to turn on highlighting, then call the
function and that works.

set hlsearch | call Find("hello")

Is there a way to turn on highlighting within the function?

Bill

--
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:

Post a Comment