Friday, March 22, 2013

Re: Motion for C functions

On 2013–03–22 Ben Fritz wrote:

> I don't think Vim does have an understanding of functions.

You're totally right. But vim has a mechanism to navigate functions,
given they are formatted in a particular way. And that was what I
was referring to.

> It knows about { or } in the first column (the [[ and ][ motions
> which you're using in your mapping).

Indeed, the column matters.

> I have 'selection' set to "exclusive". If I change it to
> "inclusive" then I get 8 lines.

I didn't know about these options before.

> Looking at WHAT gets copied with yif leads me to the following
> solution:
>
> onoremap if :<C-U>normal! [[vi{h<cr>
>
> This will work if 'selection' is set to "inclusive". If
> "exclusive" then you need to leave off the h as you did before. If
> you want to make your mapping generic you'll probably need to use
> an <expr> mapping which checks the value of the 'selection'
> option.

That's not necessary. I wasn't even aware of the existence of this
setting. After having read the help page, it seems unlikely that I
will change it. Thanks for your help.

Marco

No comments:

Post a Comment