On 5/14/06, Benji Fisher <[EMAIL PROTECTED]> wrote:
On Sun, May 14, 2006 at 03:37:26PM +0000, Yakov Lerner wrote:
> Hello,
>
> I use my own mapping of  'n' which  invokes ":normal! n" inside.
> I noticed that my n does not turn on 'hls' automatically
> when 'hls' is disabled by 'h' in viminfo. This is strange because
> my map for n does invoke ':normal! n', which itself
> would turn hls on. Here is test case:
>    vim --noplugin -u yy.vim yy.vim
>    /.<cr>
>    ZZ
>    vim --noplugin -u yy.vim yy.vim
>    gg
>    n
>    ZZ
> - this works, turns on 'hls'
>    vim --noplugin -u xx.vim xx.vim
>    " assume search pattern "." comes from viminfo
>    n
> - does not turn on 'hls'
>
> Yakov
> --------------- xx.vim -----------------
> set nocp
> :set viminfo='20,<50,s10,:20,h
> :set hls
> function! MySearch_n()
>    :silent! exe "normal! n"
> endfu
> nmap <silent>n :call MySearch_n()<cr>
> --------------------------------------------------
> 2.
> ------------------ yy.vim -------------------
> set nocp
> :set viminfo='20,<50,s10,:20,h
> :set hls
> nmap <silent>n :silent! exe "normal! n"<cr>
> --------------------------------------------

    Is there a reason to use :exe "normal! n" instead of simply
:normal! n ?  I assume this is a simplified version of something
real...

    The main difference is that xx.vim wraps the "normal! n" command in
a function.  At the very end of

:help :function-verbose

just above

:help :endfunction

the docs say

                       The last used search pattern and the redo command "."
                       will not be changed by the function.

I guess the "last used search pattern" is the thing used by :s// ; I do
not think it is exactly the same as @/. though these are usually the
same.  I guess that, as a side effect of this special rule for
functions, search highlighting is left turned off.

    I have not tried it inside a function, but

:set hls

seems to undo the effect of

:nohls

so perhaps a work-around is to add

:if &hls | set hls | endif

either to the function or (replacing "|" by "<Bar>") to the mapping.

Yes, adding '<bar>set hls' to rhs of the mapping (outside
function) solves it. (But adding ':set hls' inside function
doesn't). I realize now that this is probably by design.

Thanks
Yakov

Reply via email to