Visual Studio Tags Support | CodeGuru

Visual Studio Tags Support

–> Environment: VC6 (probably any VC) What’s all this then? Having programmed on a UNIX platform, where I used the vi editor, and since then on a PC using Lemmy, I have missed the ability to use tags when using Visual Studio. The macro published here provides tags support. To use the macro file, simply […]

Written By
CodeGuru Staff
CodeGuru Staff
Mar 6, 2001
3 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

–>

Environment: VC6 (probably any VC)

What’s all this then?

Having programmed on a UNIX platform, where I used the vi editor, and since
then on a PC using Lemmy, I have
missed the ability to use tags when using Visual Studio. The macro published
here provides tags support.

To use the macro file, simply put it in the Common\MSDev98\Macros directory
under where-ever your Visual Studio is installed. The macro file exposes two
functions (listed below). These functions can be mapped to keys
of your choice.

The functions are as follows:

PushContext:
Invoking this function picks up the currently selected text, and looks for a
reference to it in the tags file. If it finds it in the file, it then opens
the file it is contained in and jumps to the correct line or text. The current
cursor position (and file) is added to the tag stack.

PopContext:
This function will take the top entry from the tag stack, and jump to the file
and cursor position listed there. This enables you to jump to a definition, and
then come back to where you were previously working. This works regardless of
whether the tag jumped to was in the same file or a different file.

So why not use the browser facilities built-in to Visual Studio?

One of the things I like about tags that the browser info doesn’t give me is
the ability to stack the tags, so I jump back to where I came from.

Mmm, looks useful, but how do I generate my tags?

To generate my tags I use Exuberant Ctags, by Darren Hiebert. This is
available as a free download from
http://ctags.sourceforge.net/
. One thing to be careful of is that if you
create the tags file by specifying a directory, then the file paths are
stored as relative paths in the tags file. This then causes problems, as
Visual Studio may change its current directory each time you open a file.

How it works

When you first execute the PushContext function, the tags file is sought in
the directory in which the current file lives. If it is found, then its
contents are read in line by line, and the tag text is added to a dictionary,
along with the tag information (file path, and line number or search text).
(This does mean that the first time you read a tags file, there is a bit of
a delay, but after that it is quite fast.)

A separate dictionary is kept for each tags file you read, and a dictionary
of dictionaries is used to get back the correct dictionary. This means that
different directories can use different tags files.

Before reading in a tags file, the master dictionary is searched to see if
there is already a dictionary for that file. If there is, then the time stamp
of the file is compared to a saved timestamp in the dictionary, to see if the
tags file needs re-reading. This enables you to update your tags at any time,
and still be able to use them correctly.

Advertisement

Limitations

If the tag text is listed in the file more than once, then the only the first
occurance will be used. To avoid this causing problems, use care when creating
your tags file, to ensure that the more important files are scanned first, and
generate a non-sorted tags file.

Downloads

Download source – 3 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.