Question

I often find myself reading other developer's C code containing expressions like

 ptr->member1.member2[i].another_member.final_member = 42;

and needing to find out what type final_member is. Usually what I do is to track down the chain of types using C tags, starting at the declaration of ptr and digging my way into the chain of members. This is cumbersome and often I'm stuck somewhere scratching my head, asking myself "What was the next member in the chain?" To make matters worse, a simple grep for final_member in the source tree turns up too many false positives due to the name being reused in more than one struct.

Is there a way to make vim give me the answer directly? I'm willing to install any plugin and even type a few characters while the cursor is on the final_member or select the whole expression :-) Non-GUI solutions preferred.

Was it helpful?

Solution 2

I really suggest you to use plugin clang_complete (or some other plugin powered by clang) for completion. It will give you pure completion of C/C++/Objective-C code by real compiler, not ugly method by tags. Each item in completion menu also has type of field (that's what you are looking for)

Omnicppcomplete fails often on complicated expressions. Clang works great, since it is real awesome compiler.

OTHER TIPS

If i'm working on a project with several nested structs i add preview to the completeopt option.

In combination with the excellent omnicppcomplete plugin a tiny scratch window pops up if you select an entry in the completion menu. That scratch window shows some properties of the selected tag. Among other things it contains the search pattern for the tag which in case of a struct member usually contains its datatype.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top