weilbith
weilbith

Reputation: 654

Vim - Get All Tags Of A Buffer


I wanna know if anybody is aware about the possibility to get in Vim all tags for the current/specific buffer. Should mean ignoring how the tags are generated, don't matter if as a single project file or stored anywhere outside. As long as Vim could find tags for that buffer I like to get this whole "snippet" as return. So of cause it's easily possible to search for a tag and get the buffer/file plus position, but how to do this in reverse, having a buffer and getting all related tags?
Of cause I read a lot of documentation and searched a while for it, but it's seems like this direction of working with tags isn't a topic anywhere. Some suggestions by anyone? Thank you!

Upvotes: 1

Views: 1065

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172598

Vim has the tagfiles() and taglist() functions. The latter will provide a List of objects that have tag name, filespec, and some attributes. If you pass a regular expression that matches any tag (.*), you'll get a (potentially huge) list of all tags.

Tags are not directly scoped to the current buffer. The 'tags' option provides the sources of tags (which can be queried via the mentioned tagfiles()). That option value can be global, or overridden by a particular buffer.

You're right, many tags-related plugins invoke ctags et al. directly and parse the output. I guess that's because the taglist() function didn't exist in older Vim versions (or it doesn't provide information that the plugin needs).

Upvotes: 3

Related Questions