On Tue, Apr 11, 2006 at 01:34:31PM +0000, Yakov Lerner wrote:
> On 4/11/06, Anatoli Sakhnik <[EMAIL PROTECTED]> wrote:
> > Hello!
> > Can anyone tell me what's wrong in the following function. I select
> > something, press \/, enter _graph on the prompt and get another prompt
> > immediately...
> >
> > function! VisualRangeSearch(flags)
> >     let pat = input("'<,'>/")
> >     let s = '\%V'.pat
> >     call search(s, a:flags)
> > endf
> >
> > vnoremap <Leader>/ :call VisualRangeSearch('')
> > vnoremap <Leader>? :call VisualRangeSearch('b')
> 
> Something strange is going on here.
> I simplified the testcase to 1 liner:
> 
>     vnoremap \\ :call input(line('.').col('.').'>>>')<cr>
> 
> If you visual-select multiple lines and press \\,
> you'll see that input() is called multiple times, once
> for each selected line. Strange.
> 
> Yakov

     I think this is expected behavior.  When you select several lines
in Visual mode and then use : to enter Command-Line mode, a range is
inserted automatically.  In the second, simplified, example, try leaving
off the <cr> to see what is happening.  What happens then is explained
under

:help :call

     For the original example, you have to tell vim that the
user-defined function will handle the range itself (even if the function
decides to ignore the range).

:help function-range-example

(Hey, that is the paragraph following :help :call .)  Perhaps a simpler
method is to remove the range.  For example,

:vnoremap \\ :<c-u>call input(line('.').col('.').'>>>')<cr>

HTH                                     --Benji Fisher

Reply via email to