Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim - Show data type

Tags:

c

vim

ide

I typically code most of my C projects in Vim. I am comfortable with navigation, search and replace, and indexing via Ctags/Cscope.

One feature I would like to have, if possible, is a keymapping that will show the datatype for a variable under the cursor on screen.

For example, if my cursor is on a variable, "test123" (ie: int test123 = 0) is there a way to have the type (int) and some other details about the variable shown in another tab within Vim?

Also, is there something similar that would do the same for a struct variable, and show a list of all its members in the descriptive tab as well as the type (ie: struct)?

I've also noticed that sometimes while coding, I have a tab titled "[Scratch][Preview]" at the top of Vim that appears to fulfill this requirement, but I have no idea what triggers it (searches and Ctag searches don't seem to trigger it). It looks like so:

name: myStruct::instanceOfStrct|  2 cmd: /^   int instanceOfStrct;$/
.. (up a dir)                  |  3 kind: m
</code/test/test.c             |  4 struct:   myStruct
|+config/                      |  5 access:   public
|+lib/                         |  6 filename: /code/test/test.c

I think this is something that already exists in Vim to some extent, but I have not idea how to work with it.

Thank you.

like image 684
Cloud Avatar asked May 04 '12 16:05

Cloud


1 Answers

I do not know of any plugin that does what you want, however it should be quite possible using libclang. There is a fork of clang_complete that adds 'go to definition' functionality which is close to what you want. However development on that plugin seems to have stagnated.

Also the scratch buffer appears when doing autocompletion to give more information about a specific completion. It can be enabled and disabled using the completeopt setting.

like image 139
David Brown Avatar answered Sep 20 '22 13:09

David Brown