On 2010-03-10, John Beckett wrote:
> Paul wrote:
> > I did this and it worked. However, I was able to further
> > narrow down the cause of why this wasn't working for me, and
> > I think it's a bug!
> >
> > {
> >      The search happens when inside a block like this }
> >
> > but {
> >      doesn't work when in one like this!
> > }
> 
> Vim expects a C function to start with a '{' at the left margin.
> The problem is that the script uses '[[' to find the beginning
> of the function. From ':help [[':
>     [[ ... to the previous '{' in the first column.
> 
> Question to group:
> Is there a good way to jump to the start of the current function
> in a case like the following (or in other languages like
> Python)?
> 
> int func() {
>     int a = 1;
>     if ( whatever ) {
>         a = something();   // say cursor is on '='
>     }
>     return a;
> }

If you scroll to the bottom of the section which contains the target
of ":help [[", you'll find this:

    If your '{' or '}' are not in the first column, and you would
    like to use "[[" and "]]" anyway, try these mappings: >
       :map [[ ?{<CR>w99[{
       :map ][ /}<CR>b99]}
       :map ]] j0[[%/{<CR>
       :map [] k$][%?}<CR>

I tried the [[ mapping in this message and it did find the opening { 
of func().  The disadvantage to this particular set of mappings is
that they affect the search register.  A better approach would be to
do the searching within functions and have the mappings call those
functions.  I've written a plugin that does this.  I'll post it here
if anyone is interested.

Regards,
Gary

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

Reply via email to