Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim: display the type of C aggregate (struct/union) members, even when nested

Tags:

c

types

vim

ctags

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.

like image 442
Jens Avatar asked Nov 03 '22 17:11

Jens


1 Answers

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.

like image 50
user1146332 Avatar answered Dec 11 '22 00:12

user1146332