Wednesday, September 29, 2010

Re: Question? passing visual selection to function

On Sep 29, 1:32 pm, Christian Brabandt <cbli...@256bit.org> wrote:
> Hi Bee!
>
> On Mi, 29 Sep 2010, Bee wrote:
>
> > Question? passing visual selection to function
>
> > The function BlkInc() puts line numbers at the start of line.
>
> > EXAMPLE 1 works
> > EXAMPLE 2 does not work
>
> Please explain what you expect and what you observe.
>
> > Can you explain why?
>
> > ""-----=-------=-------=-------=-------=-------=-------=-------=
> > " EXAMPLE 1
> > function! BlkNum()
> >   '<,'>s/^/\=BlkInc()/
> > endfun
> > vmap <F5> :<C-U>call BlkNum()<cr>
>
> Here are you using the :s command on each visual selected line
>
> > ""-----=-------=-------=-------=-------=-------=-------=-------=
> > " EXAMPLE 2
> > function! BlkNum()
> >   s/^/\=BlkInc()/
> > endfun
> > vmap <F5> :call BlkNum()<cr>
>
> This will probably only put your line number only in the first visual
> selected line, because your :s command does not know, on which range to
> act.

Yes, you are correct as what happens in both situations.

I would have thought the visual selection in EXAMPLE 2 would have been
passed to the :s to be used on each line. But as you also observed, it
is not. EXAMPLE 2 labels each selected line as though it were the
first line.

Is EXAMPLE 1 the only way to pass the selection to :s?
Making it necessary to preceed the :call with <C-U> ?

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