Let say I have this function in menu.vim:
function! s:Test()
let search = '\d\+'
let @/ = search
return "normal n"
endfunction
Why doesn’t this highlight the search matches?
Only after I do :set hls in the commandline it does highlighting.
It does also highlighting when I push the n key on my keyboard.
If I put the same line (:set hls) in the function it doesn’t work.
BTW highlighting is enabled in my VIM.
It highlights fine if I use the commandline.
That behaviour might actually be described in the manual under
:help functions-search-undo, but there is no mention of any workaround.The documentation on
:nohlsearchalso mention this: