Shortcut to jump to the start of the current method in C++

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Shortcut to jump to the start of the current method in C++

Dun Peal
I'm looking for ways to quickly navigate and/or get contextual
information about the structure of a large C++ codebase I'm editing in
Vim.

I discovered `[m` which is supposed to go the the start of the method
in which the cursor currently resides. Instead, if the class
containing the method is itself inside a block (such as a C++
namespace, as is very often the case), the cursor will go to to the
start of the **class** instead of the start of the **method**.

For example, in the following code snippet

    namespace Foo {
      class Bar {
        void qux()
        {
          // press [m with the cursor here -> *
        }
      }
    }

Pressing [m at the asterisk will go to the start of class Bar instead
of method qux.

Is there a trivial way to fix `[m` to work as advertised?  If not, is
there an alternative, perhaps as a plugin?

Thanks, D.

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Shortcut to jump to the start of the current method in C++

Luc Hermitte
Hi,

> I'm looking for ways to quickly navigate and/or get contextual
> information about the structure of a large C++ codebase I'm editing
> in Vim.
>
> [...]
> Is there a trivial way to fix `[m` to work as advertised?  If not, is
> there an alternative, perhaps as a plugin?

The only solution I've found so far consist in using an external tools to obtain function boundaries, and from there having a way to fi [m, ]m, and even provide a "select-function" operator.

I've implemented a solution in my lh-cpp plugin [1] which requires a few other plugins [2] to work. In particular, in this case there is no way to avoid lh-dev and lh-tags dependencies.
The solution implemented has been described on vi.SE [3]

[1] https://github.com/LucHermitte/lh-cpp/
[2] https://github.com/LucHermitte/lh-cpp/#installation
[3] https://vi.stackexchange.com/a/7942/626

Regards,

--
Luc Hermitte

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.